Best Python code snippet using Airtest
recorder_test.py
Source:recorder_test.py
...31 self.assertEqual(None, self._recorder.get_recording_pattern_id())32 def test_isRecordingWhileAfterStopped_returnsFalse(self):33 self._recorder.start_recording('even')34 self._feed_even_pattern(1000)35 self._recorder.stop_recording()36 self.assertEqual(False, self._recorder.is_recording())37 def test_getRecordingPatternIdAfterStopped_returnsNone(self):38 self._recorder.start_recording('even')39 self._feed_even_pattern(1000)40 self._recorder.stop_recording()41 self.assertEqual(None, self._recorder.get_recording_pattern_id())42 def test_isRecordingAfterStart_returnsTrue(self):43 self._recorder.start_recording('even')44 self.assertEqual(True, self._recorder.is_recording())45 def test_getRecordingPatternAfterStart_returnsId(self):46 self._recorder.start_recording('even')47 self.assertEqual('even', self._recorder.get_recording_pattern_id())48 def test_playWithNoRecording_playbackReturnsFalse(self):49 self._feed_even_pattern(1000)50 self.assertFalse(self._recorder.play('non-existent-id'))51 self.assertFalse(self._recorder.play('non-existent-id', loop=True))52 self.assertEqual([], self._data_played)53 def test_recordAndPlayNonexistentPattern_noPlaybackOnDifferentPattern(self):54 self._recorder.start_recording('even')55 self._feed_even_pattern(1000)56 self._recorder.stop_recording()57 self.assertFalse(self._recorder.play('non-existent-id'))58 self.assertFalse(self._recorder.play('non-existent-id', loop=True))59 self.assertEqual([], self._data_played)60 def test_playRecordedPattern_playbackPlaysOnce(self):61 self._recorder.start_recording('even')62 self._feed_even_pattern(1000)63 self._recorder.stop_recording()64 self._feed_odd_pattern(6000)65 result = self._recorder.play('even')66 self.assertEqual(True, result)67 # Make sure notes are played back correctly in time.68 history = []69 self._scheduler.idle()70 history.append(self._data_played[:])71 for _ in range(6):72 # Each step is 1 second73 self._clock.advance(1)74 self._scheduler.idle()75 history.append(self._data_played[:])76 self.assertEqual([77 [0, 10], # Before loop, first idle call78 [0, 10, 2, 12], # Loop 079 [0, 10, 2, 12, 4, 14],80 [0, 10, 2, 12, 4, 14, 6, 16],81 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # No new notes expected after.82 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],83 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18]],84 history)85 def test_playRecordedPatternWithLoop_playbackLoops(self):86 self._recorder.start_recording('even')87 self._feed_even_pattern(1000)88 self._recorder.stop_recording()89 self._feed_odd_pattern(6000)90 result = self._recorder.play('even', loop=True, loop_delay_ms=0)91 self.assertEqual(True, result)92 # Make sure notes are played back correctly in time.93 history = []94 self._scheduler.idle()95 history.append(self._data_played[:])96 for _ in range(6):97 # Each step is 1 second98 self._clock.advance(1)99 self._scheduler.idle()100 history.append(self._data_played[:])101 self.assertEqual([102 [0, 10], # Before loop, first idle call103 [0, 10, 2, 12], # Loop 0104 [0, 10, 2, 12, 4, 14],105 [0, 10, 2, 12, 4, 14, 6, 16],106 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10], # no loop delay107 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12],108 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14]],109 history)110 def test_playRecordedPatternWithLoopAndLoopDelay_playLoopsWithDelay(self):111 self._recorder.start_recording('even')112 self._feed_even_pattern(1000)113 self._recorder.stop_recording()114 self._feed_odd_pattern(6000)115 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)116 self.assertEqual(True, result)117 # Make sure notes are played back correctly in time.118 history = []119 self._scheduler.idle()120 history.append(self._data_played[:])121 for _ in range(6):122 # Each step is 1 second123 self._clock.advance(1)124 self._scheduler.idle()125 history.append(self._data_played[:])126 self.assertEqual([127 [0, 10], # Before loop, first idle call128 [0, 10, 2, 12], # Loop 0129 [0, 10, 2, 12, 4, 14],130 [0, 10, 2, 12, 4, 14, 6, 16],131 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay132 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],133 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12]],134 history)135 def test_playMultipleRecordedPattern_playbackWorks(self):136 self._recorder.start_recording('even')137 self._feed_even_pattern(1000)138 self._recorder.stop_recording()139 self._recorder.start_recording('odd')140 self._feed_odd_pattern(6000)141 self._recorder.stop_recording()142 result = self._recorder.play('even')143 self.assertEqual(True, result)144 result = self._recorder.play('odd')145 self.assertEqual(True, result)146 # Make sure notes are played back correctly in time.147 history = []148 self._scheduler.idle()149 history.append(self._data_played[:])150 for _ in range(6):151 # Each step is 1 second152 self._clock.advance(1)153 self._scheduler.idle()154 history.append(self._data_played[:])155 # The notes will be jumbled, so we need to filter them out by even and156 # odds and compare157 even_history = [[v for v in data if v % 2 == 0] for data in history]158 odd_history = [[v for v in data if v % 2 == 1] for data in history]159 self.assertEqual([160 [0, 10], # Before loop, first idle call161 [0, 10, 2, 12], # Loop 0162 [0, 10, 2, 12, 4, 14],163 [0, 10, 2, 12, 4, 14, 6, 16],164 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # No new notes expected after.165 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],166 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18]],167 even_history)168 self.assertEqual([169 [1, 11], # Before loop, first idle call170 [1, 11, 3, 13], # Loop 0171 [1, 11, 3, 13, 5, 15],172 [1, 11, 3, 13, 5, 15, 7, 17],173 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19], # No new notes expected after.174 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19],175 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19]],176 odd_history)177 def test_playMultiplePatternsOneLoops_oneLoopsAndOtherDoesnt(self):178 self._recorder.start_recording('even')179 self._feed_even_pattern(1000)180 self._recorder.stop_recording()181 self._recorder.start_recording('odd')182 self._feed_odd_pattern(6000)183 self._recorder.stop_recording()184 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)185 self.assertEqual(True, result)186 result = self._recorder.play('odd')187 self.assertEqual(True, result)188 # Make sure notes are played back correctly in time.189 history = []190 self._scheduler.idle()191 history.append(self._data_played[:])192 for _ in range(6):193 # Each step is 1 second194 self._clock.advance(1)195 self._scheduler.idle()196 history.append(self._data_played[:])197 # The notes will be jumbled, so we need to filter them out by even and198 # odds and compare199 even_history = [[v for v in data if v % 2 == 0] for data in history]200 odd_history = [[v for v in data if v % 2 == 1] for data in history]201 self.assertEqual([202 [0, 10], # Before loop, first idle call203 [0, 10, 2, 12], # Loop 0204 [0, 10, 2, 12, 4, 14],205 [0, 10, 2, 12, 4, 14, 6, 16],206 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay207 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],208 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12]],209 even_history)210 self.assertEqual([211 [1, 11], # Before loop, first idle call212 [1, 11, 3, 13], # Loop 0213 [1, 11, 3, 13, 5, 15],214 [1, 11, 3, 13, 5, 15, 7, 17],215 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19], # No new notes expected after.216 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19],217 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19]],218 odd_history)219 def test_stopWhilePlayRecordedPattern_successfullyStops(self):220 self._recorder.start_recording('even')221 self._feed_even_pattern(1000)222 self._recorder.stop_recording()223 self._feed_odd_pattern(6000)224 result = self._recorder.play('even')225 self.assertEqual(True, result)226 # Make sure notes are played back correctly in time.227 history = []228 self._scheduler.idle()229 history.append(self._data_played[:])230 for i in range(6):231 if i == 3:232 self._recorder.stop('even')233 # Each step is 1 second234 self._clock.advance(1)235 self._scheduler.idle()236 history.append(self._data_played[:])237 self.assertEqual([238 [0, 10], # Before loop, first idle call239 [0, 10, 2, 12], # Loop 0240 [0, 10, 2, 12, 4, 14],241 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. Stops before loop 3242 [0, 10, 2, 12, 4, 14, 6, 16],243 [0, 10, 2, 12, 4, 14, 6, 16],244 [0, 10, 2, 12, 4, 14, 6, 16]],245 history)246 def test_stopWhilePlayingMultipleRecordedPattern_stopsOneOtherPlays(self):247 self._recorder.start_recording('even')248 self._feed_even_pattern(1000)249 self._recorder.stop_recording()250 self._recorder.start_recording('odd')251 self._feed_odd_pattern(6000)252 self._recorder.stop_recording()253 result = self._recorder.play('even')254 self.assertEqual(True, result)255 result = self._recorder.play('odd')256 self.assertEqual(True, result)257 # Make sure notes are played back correctly in time.258 history = []259 self._scheduler.idle()260 history.append(self._data_played[:])261 for i in range(6):262 if i == 3:263 self._recorder.stop('even')264 # Each step is 1 second265 self._clock.advance(1)266 self._scheduler.idle()267 history.append(self._data_played[:])268 # The notes will be jumbled, so we need to filter them out by even and269 # odds and compare270 even_history = [[v for v in data if v % 2 == 0] for data in history]271 odd_history = [[v for v in data if v % 2 == 1] for data in history]272 # Even wil stop after loop 2273 self.assertEqual([274 [0, 10], # Before loop, first idle call275 [0, 10, 2, 12], # Loop 0276 [0, 10, 2, 12, 4, 14],277 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. Stopped after this.278 [0, 10, 2, 12, 4, 14, 6, 16],279 [0, 10, 2, 12, 4, 14, 6, 16],280 [0, 10, 2, 12, 4, 14, 6, 16]],281 even_history)282 self.assertEqual([283 [1, 11], # Before loop, first idle call284 [1, 11, 3, 13], # Loop 0285 [1, 11, 3, 13, 5, 15],286 [1, 11, 3, 13, 5, 15, 7, 17],287 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19], # No new notes expected after.288 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19],289 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19]],290 odd_history)291 def test_stopNonExistentPattern_noImpact(self):292 self._recorder.start_recording('even')293 self._feed_even_pattern(1000)294 self._recorder.stop_recording()295 self._recorder.start_recording('odd')296 self._feed_odd_pattern(6000)297 self._recorder.stop_recording()298 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)299 self.assertEqual(True, result)300 result = self._recorder.play('odd')301 self.assertEqual(True, result)302 # Make sure notes are played back correctly in time.303 history = []304 self._scheduler.idle()305 history.append(self._data_played[:])306 for _ in range(6):307 self._recorder.stop('non-existent-pattern')308 # Each step is 1 second309 self._clock.advance(1)310 self._scheduler.idle()311 history.append(self._data_played[:])312 # The notes will be jumbled, so we need to filter them out by even and313 # odds and compare314 even_history = [[v for v in data if v % 2 == 0] for data in history]315 odd_history = [[v for v in data if v % 2 == 1] for data in history]316 self.assertEqual([317 [0, 10], # Before loop, first idle call318 [0, 10, 2, 12], # Loop 0319 [0, 10, 2, 12, 4, 14],320 [0, 10, 2, 12, 4, 14, 6, 16],321 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay322 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],323 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12]],324 even_history)325 self.assertEqual([326 [1, 11], # Before loop, first idle call327 [1, 11, 3, 13], # Loop 0328 [1, 11, 3, 13, 5, 15],329 [1, 11, 3, 13, 5, 15, 7, 17],330 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19], # No new notes expected after.331 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19],332 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19]],333 odd_history)334 def test_stopAllWhileNotPlaying_noImpact(self):335 self._recorder.start_recording('even')336 self._feed_even_pattern(1000)337 self._recorder.stop_recording()338 self._recorder.stop_all()339 self._clock.advance(1)340 self._scheduler.idle()341 self.assertEqual([], self._data_played)342 def test_stopAllWhilePlayingMultiple_stopsAll(self):343 self._recorder.start_recording('even')344 self._feed_even_pattern(1000)345 self._recorder.stop_recording()346 self._recorder.start_recording('odd')347 self._feed_odd_pattern(6000)348 self._recorder.stop_recording()349 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)350 self.assertEqual(True, result)351 result = self._recorder.play('odd')352 self.assertEqual(True, result)353 # Make sure notes are played back correctly in time.354 history = []355 self._scheduler.idle()356 history.append(self._data_played[:])357 for i in range(6):358 if i == 3:359 self._recorder.stop_all()360 self._clock.advance(1)361 self._scheduler.idle()362 history.append(self._data_played[:])363 # The notes will be jumbled, so we need to filter them out by even and364 # odds and compare365 even_history = [[v for v in data if v % 2 == 0] for data in history]366 odd_history = [[v for v in data if v % 2 == 1] for data in history]367 self.assertEqual([368 [0, 10], # Before loop, first idle call369 [0, 10, 2, 12], # Loop 0370 [0, 10, 2, 12, 4, 14],371 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. Stopped after this.372 [0, 10, 2, 12, 4, 14, 6, 16],373 [0, 10, 2, 12, 4, 14, 6, 16],374 [0, 10, 2, 12, 4, 14, 6, 16]],375 even_history)376 self.assertEqual([377 [1, 11], # Before loop, first idle call378 [1, 11, 3, 13], # Loop 0379 [1, 11, 3, 13, 5, 15],380 [1, 11, 3, 13, 5, 15, 7, 17], # Loop 2. Stopped after this.381 [1, 11, 3, 13, 5, 15, 7, 17],382 [1, 11, 3, 13, 5, 15, 7, 17],383 [1, 11, 3, 13, 5, 15, 7, 17]],384 odd_history)385 def test_stopWhilePlayingLoop_stopsLoop(self):386 self._recorder.start_recording('even')387 self._feed_even_pattern(1000)388 self._recorder.stop_recording()389 self._feed_odd_pattern(6000)390 result = self._recorder.play('even', loop=True)391 self.assertEqual(True, result)392 # Make sure notes are played back correctly in time.393 history = []394 self._scheduler.idle()395 history.append(self._data_played[:])396 for i in range(6):397 if i == 3:398 self._recorder.stop('even')399 # Each step is 1 second400 self._clock.advance(1)401 self._scheduler.idle()402 history.append(self._data_played[:])403 self.assertEqual([404 [0, 10], # Before loop, first idle call405 [0, 10, 2, 12], # Loop 0406 [0, 10, 2, 12, 4, 14],407 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. Stops before loop 3408 [0, 10, 2, 12, 4, 14, 6, 16],409 [0, 10, 2, 12, 4, 14, 6, 16],410 [0, 10, 2, 12, 4, 14, 6, 16]],411 history)412 def test_cancelLoopWhenNotLooping_finishes(self):413 self._recorder.start_recording('even')414 self._feed_even_pattern(1000)415 self._recorder.stop_recording()416 self._feed_odd_pattern(6000)417 result = self._recorder.play('even')418 self.assertEqual(True, result)419 # Make sure notes are played back correctly in time.420 history = []421 self._scheduler.idle()422 history.append(self._data_played[:])423 for i in range(6):424 if i == 3:425 self._recorder.cancel_loop('even')426 # Each step is 1 second427 self._clock.advance(1)428 self._scheduler.idle()429 history.append(self._data_played[:])430 self.assertEqual([431 [0, 10], # Before loop, first idle call432 [0, 10, 2, 12], # Loop 0433 [0, 10, 2, 12, 4, 14],434 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. looping canceled.435 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],436 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],437 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18]],438 history)439 def test_cancelLoopWhileLooping_loopStopsButPlaybackFinishes(self):440 self._recorder.start_recording('even')441 self._feed_even_pattern(1000)442 self._recorder.stop_recording()443 self._feed_odd_pattern(6000)444 result = self._recorder.play('even', loop=True)445 self.assertEqual(True, result)446 # Make sure notes are played back correctly in time.447 history = []448 self._scheduler.idle()449 history.append(self._data_played[:])450 for i in range(6):451 if i == 3:452 self._recorder.cancel_loop('even')453 # Each step is 1 second454 self._clock.advance(1)455 self._scheduler.idle()456 history.append(self._data_played[:])457 self.assertEqual([458 [0, 10], # Before loop, first idle call459 [0, 10, 2, 12], # Loop 0460 [0, 10, 2, 12, 4, 14],461 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. looping canceled.462 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],463 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],464 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18]],465 history)466 def test_cancelNonexistentLoopDuringLoopPlayback_noImpact(self):467 self._recorder.start_recording('even')468 self._feed_even_pattern(1000)469 self._recorder.stop_recording()470 self._feed_odd_pattern(6000)471 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)472 self.assertEqual(True, result)473 # Make sure notes are played back correctly in time.474 history = []475 self._scheduler.idle()476 history.append(self._data_played[:])477 for i in range(6):478 if i == 3:479 self._recorder.cancel_loop('non-existent-id')480 # Each step is 1 second481 self._clock.advance(1)482 self._scheduler.idle()483 history.append(self._data_played[:])484 self.assertEqual([485 [0, 10], # Before loop, first idle call486 [0, 10, 2, 12], # Loop 0487 [0, 10, 2, 12, 4, 14],488 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. looping canceled.489 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],490 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],491 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12]],492 history)493 def test_cancelLoopWhilePlayingMultiple_stopsOneOtherLoops(self):494 self._recorder.start_recording('even')495 self._feed_even_pattern(1000)496 self._recorder.stop_recording()497 self._recorder.start_recording('odd')498 self._feed_odd_pattern(6000)499 self._recorder.stop_recording()500 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)501 self.assertEqual(True, result)502 result = self._recorder.play('odd', loop=True, loop_delay_ms=1000)503 self.assertEqual(True, result)504 # Make sure notes are played back correctly in time.505 history = []506 self._scheduler.idle()507 history.append(self._data_played[:])508 for i in range(6):509 if i == 3:510 self._recorder.cancel_loop('even')511 # Each step is 1 second512 self._clock.advance(1)513 self._scheduler.idle()514 history.append(self._data_played[:])515 # The notes will be jumbled, so we need to filter them out by even and516 # odds and compare517 even_history = [[v for v in data if v % 2 == 0] for data in history]518 odd_history = [[v for v in data if v % 2 == 1] for data in history]519 # Even wil stop after loop 2520 self.assertEqual([521 [0, 10], # Before loop, first idle call522 [0, 10, 2, 12], # Loop 0523 [0, 10, 2, 12, 4, 14],524 [0, 10, 2, 12, 4, 14, 6, 16], # Loop 2. Stopped after this.525 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],526 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18],527 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18]],528 even_history)529 self.assertEqual([530 [1, 11], # Before loop, first idle call531 [1, 11, 3, 13], # Loop 0532 [1, 11, 3, 13, 5, 15],533 [1, 11, 3, 13, 5, 15, 7, 17],534 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19],535 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19, 1, 11],536 [1, 11, 3, 13, 5, 15, 7, 17, 9, 19, 1, 11, 3, 13]],537 odd_history)538 def test_updateLoopDelayWhilePlaying_loopDelayUpdated(self):539 self._recorder.start_recording('even')540 self._feed_even_pattern(1000)541 self._recorder.stop_recording()542 self._feed_odd_pattern(6000)543 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)544 self.assertEqual(True, result)545 # Make sure notes are played back correctly in time.546 history = []547 self._scheduler.idle()548 history.append(self._data_played[:])549 for i in range(11):550 # Each step is 1 second551 if i == 4:552 self._recorder.set_loop_delay('even', 2000)553 self._clock.advance(1)554 self._scheduler.idle()555 history.append(self._data_played[:])556 self.assertEqual([557 [0, 10], # Before loop, first idle call558 [0, 10, 2, 12], # Loop 0559 [0, 10, 2, 12, 4, 14],560 [0, 10, 2, 12, 4, 14, 6, 16],561 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay562 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],563 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12],564 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14],565 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16],566 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16, 8,567 18],568 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16, 8,569 18], # Due to change in delay to 2 seconds570 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16, 8,571 18, 0, 10]],572 history)573 def test_whileLoopingCheckIsPlaying_shouldReturnTrue(self):574 self._recorder.start_recording('even')575 self._feed_even_pattern(1000)576 self._recorder.stop_recording()577 self._feed_odd_pattern(6000)578 self._recorder.play('even', loop=True, loop_delay_ms=1000)579 self.assertEqual(True, self._recorder.is_playing('even'))580 def test_whileLoopingCheckNonPlayingPattern_shouldReturnFalse(self):581 self._recorder.start_recording('even')582 self._feed_even_pattern(1000)583 self._recorder.stop_recording()584 self._feed_odd_pattern(6000)585 self._recorder.play('even', loop=True, loop_delay_ms=1000)586 self.assertEqual(False, self._recorder.is_playing('odd'))587 def test_whileNonLoopPlaybackCheckPlayingPattern_shouldReturnTrue(self):588 self._recorder.start_recording('even')589 self._feed_even_pattern(1000)590 self._recorder.stop_recording()591 self._feed_odd_pattern(6000)592 self._recorder.play('even', loop=False, loop_delay_ms=1000)593 self.assertEqual(True, self._recorder.is_playing('even'))594 def test_whileLoopPlaybackIsLoopingPlayingPattern_shouldReturnTrue(self):595 self._recorder.start_recording('even')596 self._feed_even_pattern(1000)597 self._recorder.stop_recording()598 self._feed_odd_pattern(6000)599 self._recorder.play('even', loop=True, loop_delay_ms=1000)600 self.assertEqual(True, self._recorder.is_looping('even'))601 def test_whileNonLoopPlaybackPlayingPattern_shouldReturnFalse(self):602 self._recorder.start_recording('even')603 self._feed_even_pattern(1000)604 self._recorder.stop_recording()605 self._feed_odd_pattern(6000)606 self._recorder.play('even', loop=False, loop_delay_ms=1000)607 self.assertEqual(False, self._recorder.is_looping('even'))608 def test_afterRecordingCheckValidPattern_shouldReturnTrue(self):609 self._recorder.start_recording('even')610 self._feed_even_pattern(1000)611 self._recorder.stop_recording()612 self.assertEqual(True, self._recorder.has_pattern('even'))613 def test_afterRecordingCheckInvalidPattern_shouldReturnFalse(self):614 self._recorder.start_recording('even')615 self._feed_even_pattern(1000)616 self._recorder.stop_recording()617 self.assertEqual(False, self._recorder.has_pattern('odd'))618 def test_recordingAnEmptyPatternCheckHasPattern_shouldReturnFalse(self):619 self._recorder.start_recording('even')620 self._recorder.stop_recording()621 self.assertEqual(False, self._recorder.has_pattern('even'))622 def test_playNoLoop_lastLoopingShouldBeNone(self):623 self._recorder.start_recording('even')624 self._feed_even_pattern(1000)625 self._recorder.stop_recording()626 self._feed_odd_pattern(6000)627 self._recorder.play('even', loop=False, loop_delay_ms=1000)628 self.assertEqual(None, self._recorder.get_last_looping_pattern_id())629 def test_playLoop_lastLoopingShouldBePattern(self):630 self._recorder.start_recording('even')631 self._feed_even_pattern(1000)632 self._recorder.stop_recording()633 self._feed_odd_pattern(6000)634 self._recorder.play('even', loop=True, loop_delay_ms=1000)635 self.assertEqual('even', self._recorder.get_last_looping_pattern_id())636 def test_playMultipleLoops_lastLoopingShouldBeLastLoopPattern(self):637 self._recorder.start_recording('even')638 self._feed_even_pattern(1000)639 self._recorder.stop_recording()640 self._recorder.start_recording('odd')641 self._feed_odd_pattern(1000)642 self._recorder.stop_recording()643 self._recorder.play('even', loop=True, loop_delay_ms=1000)644 self._recorder.play('odd', loop=True, loop_delay_ms=1000)645 self._recorder.play('adsf', loop=True, loop_delay_ms=1000)646 self.assertEqual('odd', self._recorder.get_last_looping_pattern_id())647 def test_overwritePatternWithEmptyPatternAndPlay_shouldNotPlay(self):648 self._recorder.start_recording('even')649 self._feed_even_pattern(1000)650 self._recorder.stop_recording()651 self._recorder.start_recording('even')652 self._recorder.stop_recording()653 self.assertEqual(False, self._recorder.play('even'))654 def test_updateLoopDelayStopAndRestartPlaying_loopDelayUpdated(self):655 self._recorder.start_recording('even')656 self._feed_even_pattern(1000)657 self._recorder.stop_recording()658 result = self._recorder.play('even', loop=True)659 self._recorder.set_loop_delay('even', 2000)660 self._recorder.stop_all()661 self._clock.advance(1)662 self._scheduler.idle()663 self._data_played = []664 result = self._recorder.play('even', loop=True)665 self.assertEqual(True, result)666 # Make sure notes are played back correctly in time.667 history = []668 self._scheduler.idle()669 history.append(self._data_played[:])670 for i in range(11):671 # Each step is 1 second672 self._clock.advance(1)673 self._scheduler.idle()674 history.append(self._data_played[:])675 self.assertEqual([676 [0, 10], # Before loop, first idle call677 [0, 10, 2, 12], # Loop 0678 [0, 10, 2, 12, 4, 14],679 [0, 10, 2, 12, 4, 14, 6, 16],680 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay681 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18], # w/ loop delay682 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10],683 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12],684 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14],685 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16],686 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16, 8,687 18],688 [0, 10, 2, 12, 4, 14, 6, 16, 8, 18, 0, 10, 2, 12, 4, 14, 6, 16, 8,689 18]],690 history)691 def test_callingPlayWhilePlaying_restartsPattern(self):692 self._recorder.start_recording('even')693 self._feed_even_pattern(1000)694 self._recorder.stop_recording()695 result = self._recorder.play('even', loop=True)696 self._clock.advance(2)697 self._scheduler.idle()698 result = self._recorder.play('even', loop=True, loop_delay_ms=1000)699 self.assertEqual(True, result)700 # Make sure notes are played back correctly in time.701 history = []702 self._scheduler.idle()703 history.append(self._data_played[:])704 for i in range(5):705 # Each step is 1 second706 self._clock.advance(1)707 self._scheduler.idle()708 history.append(self._data_played[:])...
schedule_recording.py
Source:schedule_recording.py
...40 record.add_status({'schedule_stop_recording': None})41 return {'error': 'EXPIRED'}42 # start Timer43 def aux_stop():44 record.stop_recording()45 record.add_status({'schedule_stop_recording': None})46 timers['stop_recording'] = {'timer': None, 'end_timestamp': None}47 t = Timer((timers['stop_recording']['end_timestamp'] - datetime.utcnow()).total_seconds(), aux_stop)48 t.start()49 # save new timer50 timers['stop_recording']['timer'] = t51 # save status52 record.add_status({'schedule_stop_recording': timers['stop_recording']['end_timestamp'].isoformat()})53 return timers['stop_recording']['end_timestamp']54'''55Schedules to stop the recording in nb_sec seconds56'''57def schedule_stop_recording(nb_sec):58 global timers59 # unschedule previous stop_recording timer60 if isinstance(timers['stop_recording'], dict) and timers['stop_recording']['timer'] != None:61 timers['stop_recording']['timer'].cancel()62 timers['stop_recording'] = {'timer': None, 'end_timestamp': None}63 # we just cancel the timer if nb_sec <= 064 if nb_sec <= 0:65 return timers['stop_recording']66 # start Timer67 t = Timer(nb_sec, record.stop_recording)68 t.start()69 # save new timer70 end_t = (datetime.utcnow() + timedelta(seconds=nb_sec)).isoformat()71 timers['stop_recording'] = {'timer': t, 'end_timestamp': end_t}...
wave_recording.py
Source:wave_recording.py
1__author__ = 'Kristy'2"""3This module controls how the audio stream is coordinated with the datastream,4and how it is recorded and saved.5"""6from threading import Thread, Event7from collections import deque8from ...ema_shared.properties import wave_writing_chunk_size9recording = None10stop_recording = Event()11def start_sound_recording(f):12 """Write to the wave file,13 performing the audio recording in a thread.14 Return a deque that contains the latest sample number written to the audio file.15 This number should be included in the TSV file when it is written.16 """17 global recording, stop_recording18 stop_recording.clear()19 last_wave_time = deque(maxlen=1)20 last_wave_time.append(0) # set a starting value21 recording = Thread(target=record_wav_to_file, args=(f, stop_recording, last_wave_time))22 recording.daemon = True23 recording.start()24 return last_wave_time25def stop_sound_recording():26 global stop_recording27 if not stop_recording.is_set():28 stop_recording.set()29def record_wav_to_file(fname, endflag, tsqueue):30 """Waiting for a flag to terminate, record all audio to the given file location.31 Inspired by http://stackoverflow.com/questions/892199/detect-record-audio-in-python"""32 import wave33 import pyaudio34 print('Initialising wave recording.')35 chunk = wave_writing_chunk_size36 FORMAT = pyaudio.paInt1637 CHANNELS = 138 RATE = 4410039 p = pyaudio.PyAudio()40 sas = p.get_sample_size(FORMAT)41 aud_stream = p.open(format=FORMAT,42 channels=CHANNELS,43 rate=RATE,44 input=True,45 frames_per_buffer=chunk)46 wf = wave.open(fname, 'wb')47 wf.setnchannels(CHANNELS)48 wf.setframerate(RATE)49 wf.setsampwidth(sas)50 aud_stream.start_stream()51 while not endflag.is_set():52 data = aud_stream.read(chunk)53 print('Saving to wav sample number', wf.tell()/(CHANNELS*16))54 tsqueue.append(wf.tell()/(CHANNELS*16)) # save the most recent sample number55 wf.writeframes(data)56 print('Ceasing wave recording.')57 aud_stream.stop_stream()58 aud_stream.close()59 p.terminate()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!