Best Python code snippet using localstack_python
finalproject.py
Source:finalproject.py
...283 song.append(['c4', 2])284 se[0].play()285 idx = 3286 tmr = 0287 return put_event()288 289 # 2ºÐ À½Ç¥ ·¹¸¦ ¸Ô¾úÀ» ½Ã290 if maze[pl_y][pl_x] == 4:291 song.append(['d4', 2])292 se[1].play()293 idx = 3294 tmr = 0295 return put_event()296 297 # 2ºÐ À½Ç¥ ¹Ì¸¦ ¸Ô¾úÀ» ½Ã298 if maze[pl_y][pl_x] == 5:299 song.append(['e4', 2])300 se[2].play()301 idx = 3302 tmr = 0303 return put_event()304 # 2ºÐ À½Ç¥ Æĸ¦ ¸Ô¾úÀ» ½Ã305 if maze[pl_y][pl_x] == 6:306 song.append(['f4', 2])307 se[3].play()308 idx = 3309 tmr = 0310 return put_event()311 312 # 2ºÐ À½Ç¥ ¼ÖÀ» ¸Ô¾úÀ» ½Ã313 if maze[pl_y][pl_x] == 7:314 song.append(['g4', 2])315 se[4].play()316 idx = 3317 tmr = 0318 return put_event()319 320 # 2ºÐ À½Ç¥ ¶ó¸¦ ¸Ô¾úÀ» ½Ã321 if maze[pl_y][pl_x] == 8:322 song.append(['a4', 2])323 se[5].play()324 idx = 3325 tmr = 0326 return put_event()327 328 # 2ºÐ À½Ç¥ ½Ã¸¦ ¸Ô¾úÀ» ½Ã329 if maze[pl_y][pl_x] == 9:330 song.append(['b4', 2])331 se[6].play()332 idx = 3333 tmr = 0334 return put_event()335 336 # 2ºÐ À½Ç¥ ³ôÀº µµ¸¦ ¸Ô¾úÀ» ½Ã337 if maze[pl_y][pl_x] == 10:338 song.append(['c5', 2])339 se[7].play()340 idx = 3341 tmr = 0342 return put_event()343 # 4ºÐ À½Ç¥ µµ¸¦ ¸Ô¾úÀ» ½Ã344 if maze[pl_y][pl_x] == 11:345 song.append(['c4', 4])346 se[0].play()347 idx = 3348 tmr = 0349 return put_event()350 351 # 4ºÐ À½Ç¥ ·¹¸¦ ¸Ô¾úÀ» ½Ã352 if maze[pl_y][pl_x] == 12:353 song.append(['d4', 4])354 se[1].play()355 idx = 3356 tmr = 0357 return put_event()358 359 # 4ºÐ À½Ç¥ ¹Ì¸¦ ¸Ô¾úÀ» ½Ã360 if maze[pl_y][pl_x] == 13:361 song.append(['e4', 4])362 se[2].play()363 idx = 3364 tmr = 0365 return put_event()366 367 # 4ºÐ À½Ç¥ Æĸ¦ ¸Ô¾úÀ» ½Ã368 if maze[pl_y][pl_x] == 14:369 song.append(['f4', 4])370 se[3].play()371 idx = 3372 tmr = 0373 return put_event()374 375 # 4ºÐ À½Ç¥ ¼ÖÀ» ¸Ô¾úÀ» ½Ã376 if maze[pl_y][pl_x] == 15:377 song.append(['g4', 4])378 se[4].play()379 idx = 3380 tmr = 0381 return put_event() 382 383 # 4ºÐ À½Ç¥ ¶ó¸¦ ¸Ô¾úÀ» ½Ã384 if maze[pl_y][pl_x] == 16:385 song.append(['a4', 4])386 se[5].play()387 idx = 3388 tmr = 0389 return put_event()390 391 # 4ºÐ À½Ç¥ ½Ã¸¦ ¸Ô¾úÀ» ½Ã392 if maze[pl_y][pl_x] == 17:393 song.append(['b5', 4])394 se[6].play()395 idx = 3396 tmr = 0397 return put_event()398 399 # 4ºÐ À½Ç¥ ³ôÀº µµ¸¦ ¸Ô¾úÀ» ½Ã400 if maze[pl_y][pl_x] == 18:401 song.append(['c5', 4])402 se[7].play()403 idx = 3404 tmr = 0405 return put_event()406 407 # 8ºÐ À½Ç¥ µµ¸¦ ¸Ô¾úÀ» ½Ã408 if maze[pl_y][pl_x] == 19:409 song.append(['c4', 8])410 se[0].play()411 idx = 3412 tmr = 0413 return put_event()414 415 # 8ºÐ À½Ç¥ ·¹¸¦ ¸Ô¾úÀ» ½Ã416 if maze[pl_y][pl_x] == 20:417 song.append(['d4', 8])418 se[1].play()419 idx = 3420 tmr = 0421 return put_event()422 423 # 8ºÐ À½Ç¥ ¹Ì¸¦ ¸Ô¾úÀ» ½Ã424 if maze[pl_y][pl_x] == 21:425 song.append(['e4', 8])426 se[2].play()427 idx = 3428 tmr = 0429 return put_event()430 431 # 8ºÐ À½Ç¥ Æĸ¦ ¸Ô¾úÀ» ½Ã432 if maze[pl_y][pl_x] == 22:433 song.append(['f4', 8])434 se[3].play()435 idx = 3436 tmr = 0437 return put_event()438 439 # 8ºÐ À½Ç¥ ¼ÖÀ» ¸Ô¾úÀ» ½Ã440 if maze[pl_y][pl_x] == 23:441 song.append(['g4', 8])442 se[4].play()443 idx = 3444 tmr = 0445 return put_event()446 447 # 8ºÐ À½Ç¥ ¶ó¸¦ ¸Ô¾úÀ» ½Ã448 if maze[pl_y][pl_x] == 24:449 song.append(['a4', 8])450 se[5].play()451 idx = 3452 tmr = 0453 return put_event()454 455 # 8ºÐ À½Ç¥ ½Ã¸¦ ¸Ô¾úÀ» ½Ã456 if maze[pl_y][pl_x] == 25:457 song.append(['b4', 8])458 se[6].play()459 idx = 3460 tmr = 0461 return put_event()462 463 # 8ºÐ À½Ç¥ ³ôÀº µµ¸¦ ¸Ô¾úÀ» ½Ã464 if maze[pl_y][pl_x] == 26:465 song.append(['c5', 8])466 se[7].play()467 idx = 3468 tmr = 0469 return put_event()470 471 # °è´Ü¿¡ ´êÀ½472 if maze[pl_y][pl_x] == 27:473 idx = 2474 tmr = 0475 return476 477 # ¿¬ÁÖÇÑ °îÀ» µéÀ» ¼ö ÀÖ´Â ¿ÀºêÁ§Æ®478 if maze[pl_y][pl_x] == 28:479 pygame.mixer.music.load("examples/makesong2.wav")480 pygame.mixer.music.play(1)481 tmr = 0482 return put_event()483 484 # ¾Ë°í¸®Áò¿¡ ÀÇÇØ ¸¸µé¾îÁø °îÀ» µéÀ» ¼ö ÀÖ´Â ¿ÀºêÁ§Æ®485 if maze[pl_y][pl_x] == 29:486 pygame.mixer.music.load("result/random_makesong2.wav")487 pygame.mixer.music.play(1)488 tmr = 0489 return put_event()490 491 if maze[pl_y][pl_x] == 37:492 stage = 1493 idx = 2494 tmr = 0495 return 496 497 # ¹æÇâ Å°·Î »óÇÏÁ¿ì À̵¿498 x = pl_x499 y = pl_y500 if key[K_UP] == 1:501 pl_d = 0502 if maze[pl_y - 1][pl_x] != 1:503 pl_y = pl_y - 1504 if key[K_DOWN] == 1:505 pl_d = 1506 if maze[pl_y + 1][pl_x] != 1:507 pl_y = pl_y + 1508 if key[K_LEFT] == 1:509 pl_d = 2510 if maze[pl_y][pl_x - 1] != 1:511 pl_x = pl_x - 1512 if key[K_RIGHT] == 1:513 pl_d = 3514 if maze[pl_y][pl_x + 1] != 1:515 pl_x = pl_x + 1516 pl_a = pl_d * 2517 if pl_x != x or pl_y != y: # À̵¿ ½Ã ½Ä·® ¹× ü·Â °è»ê518 pl_a = pl_a + tmr % 2 # À̵¿ ½Ã °È±â ¾Ö´Ï¸ÞÀ̼Ç519def put_event(): 520 global pl_x, pl_y, pl_d, pl_a521 # Ç÷¹À̾î Ãʱâ À§Ä¡522 while True:523 pl_x = 5524 pl_y = 4525 if (maze[pl_y][pl_x] == 0):526 break527 pl_d = 1528 pl_a = 2 529def draw_text(bg, txt, x, y, fnt, col): # ±×¸²ÀÚ Æ÷ÇÔÇÑ ¹®ÀÚ Ç¥½Ã530 sur = fnt.render(txt, True, BLACK)531 bg.blit(sur, [x + 1, y + 2])532 sur = fnt.render(txt, True, col)533 bg.blit(sur, [x, y])534 535def draw_para(bg, fnt): # ÁÖÀΰø ´É·Â Ç¥½Ã536 X = 30537 Y = 600538 col = WHITE539 540 list2 = []541 for x in song:542 if x[0] == 'c4':543 list2.append('Do')544 elif x[0] == 'd4':545 list2.append('Re')546 elif x[0] == 'e4':547 list2.append('Mi')548 elif x[0] == 'f4':549 list2.append('Fa')550 elif x[0] == 'g4':551 list2.append('Sol')552 elif x[0] == 'a4':553 list2.append('La')554 elif x[0] == 'b4':555 list2.append('Si')556 elif x[0] == 'c5':557 list2.append('hDo')558 559 draw_text(bg, "Melody:" + str(list2) , X , Y + 6, fnt, col)560def make_midi(midi_path, notes, bpm=120):561 note_names = 'c c# d d# e f f# g g# a a# b'.split()562 result = NoteSeq()563 for n in notes:564 duration = 1. / n[1]565 if n[0].lower() == 'r':566 result.append(Rest(dur=duration))567 else:568 pitch = n[0][:-1]569 octave = int(n[0][-1]) + 1570 pitch_number = note_names.index(pitch.lower())571 572 result.append(Note(pitch_number, octave=octave, dur=duration))573 574 midi = Midi(number_tracks=1, tempo=bpm)575 midi.seq_notes(result, track=0)576 midi.write(midi_path)577 578def main():579 global idx, tmr, stage, pl_a580 pygame.init()581 pygame.mixer.init()582 pygame.display.set_caption("Music Game")583 screen = pygame.display.set_mode((880,720))584 clock = pygame.time.Clock()585 font = pygame.font.Font(None, 40)586 fontS = pygame.font.Font(None, 30)587 588 while True:589 for event in pygame.event.get():590 if event.type == pygame.QUIT:591 pygame.quit()592 sys.exit()593 594 595 tmr = tmr + 1596 key = pygame.key.get_pressed()597 598 if idx == 0: # ŸÀÌƲ ȸé599 screen.fill(BLACK)600 screen.blit(imgTitle, [-20, 0])601 screen.blit(imgTitle2,[80, 100])602 draw_text(screen, "Press Any Key", 330, 560, font, BLINK[tmr % 6])603 if key[K_UP] or key[K_DOWN] or key[K_LEFT] or key[K_RIGHT] == 1:604 make_maze()605 put_event()606 idx = 1607 608 # 609 elif idx == 1:610 move_player(key)611 draw_maze(screen, fontS)612 draw_para(screen, fontS)613 614 if stage == 1:615 draw_text(screen, "Input Melody", 60, 40, fontS, WHITE)616 if stage == 2:617 draw_text(screen, "Listen to Input music and make music!", 60, 40, fontS, WHITE)618 619 620 621 #ȸé Àüȯ È¿°ú(¸Ç À§¿Í ¾Æ·¡) ¹× ³ë·¡ ¸¸µé±â(Áß°£ ºÎºÐ)622 elif idx == 2:623 draw_maze(screen, fontS)624 if 1 <= tmr and tmr <= 5:625 h = 80 * tmr626 pygame.draw.rect(screen, BLACK, [0,0,880,h])627 pygame.draw.rect(screen, BLACK, [0,720 - h, 880, h])628 if tmr == 5:629 stage = 1630 if stage == 1:631 stage = stage + 1632 make_maze()633 ps.make_wav(song, fn='examples/makesong2.wav')634 matrix = MusicMatrix(song)635 start_note = song[0]636 random_song = []637 for i in range(0, 30):638 start_note = matrix.next_note(start_note)639 random_song.append(start_note) 640 ps.make_wav(random_song, fn='result/random_makesong2.wav')641 put_event()642 643 if 6 <= tmr and tmr <= 9:644 h = 80 * (10 - tmr)645 pygame.draw.rect(screen, BLACK, [0,0,880,h])646 pygame.draw.rect(screen, BLACK, [0,720 - h,880,h])647 if tmr == 10:648 idx = 1649 650 elif idx == 3: # ¿ÀºêÁ§Æ® ÅÍÄ¡½Ã ¹ß»ýÇÏ´Â À̺¥Æ®651 draw_maze(screen, fontS)652 draw_text(screen, "Input Complete!", 330, 240, font, WHITE)653 if tmr == 10:654 idx = 1655 ...
local.py
Source:local.py
...54 logger.info('Move event for {}: from {} to {}'.format('directory' if event.is_directory else 'file', event.src_path, event.dest_path))55 if is_ignored(event.dest_path):56 logger.info('Removing {} {} from DB, it was moved to an ignored file'.format('directory' if event.is_directory else 'file', event.src_path, event.dest_path))57 context = OperationContext(local=Path(event.src_path), check_is_folder=False)58 return self.put_event(operations.DatabaseDelete(context))59 # Note: OperationContext should extrapolate all attributes from what it is given60 if event.is_directory:61 try:62 # TODO: avoid a lazy context load in this case to catch the NodeNotFound exception?63 _ = OperationContext(local=Path(event.src_path), is_folder=True).remote64 return self.put_event(operations.RemoteMoveFolder(65 OperationContext(local=Path(event.src_path), is_folder=True),66 OperationContext(local=Path(event.dest_path), is_folder=True),67 ))68 except NodeNotFound:69 return self.put_event(operations.RemoteCreateFolder(70 OperationContext(local=Path(event.dest_path), is_folder=True),71 ))72 try:73 # TODO: avoid a lazy context load in this case to catch the NodeNotFound exception?74 _ = OperationContext(local=Path(event.src_path)).remote # noqa75 return self.put_event(operations.RemoteMoveFile(76 OperationContext(local=Path(event.src_path)),77 OperationContext(local=Path(event.dest_path)),78 ))79 except NodeNotFound:80 return self.put_event(operations.RemoteCreateFile(81 OperationContext(local=Path(event.dest_path)),82 ))83 def on_created(self, event):84 logger.info('Creation event for {}: {}'.format('directory' if event.is_directory else 'file', event.src_path))85 node = utils.extract_node(event.src_path)86 path = Path(event.src_path)87 # If the file exists in the database, this is a modification88 # This logic may not be the most correct, #TODO re-evaluate89 if utils.local_to_db(path, node):90 return self.on_modified(event)91 context = OperationContext(local=path, node=node)92 if event.is_directory:93 return self.put_event(operations.RemoteCreateFolder(context))94 return self.put_event(operations.RemoteCreateFile(context))95 def on_deleted(self, event, *args, is_folder=False, **kwargs):96 logger.info('Deletion event for {}: {}'.format('directory' if event.is_directory else 'file', event.src_path))97 # A hack: override checking if the passed path is a directory. Since Windows98 # emits folder deletion events as file deletes we need to ignore whether or not99 # a delete event is for a folder. Since the RemoteDelete operation works identically100 # for files and folders we can get away with this here.101 context = OperationContext(local=Path(event.src_path), check_is_folder=False)102 context.db # noqa103 return self.put_event(operations.RemoteDelete(context))104 def on_modified(self, event):105 logger.info('Modification event for {}: {}'.format('directory' if event.is_directory else 'file', event.src_path))106 node = utils.extract_node(event.src_path)107 path = Path(event.src_path)108 # If the file does not exist in the database, this may be a create109 if not utils.local_to_db(path, node):110 # for e in self._create_cache:111 # if e.src_path == event.src_path:112 # logging.warning('Found a duplicate create event {}. Ignoring...'.format(event))113 # return114 return self.on_created(event)115 context = OperationContext(local=Path(event.src_path))116 if event.is_directory:117 # FIXME: This branch should never be reached, due to a check in dispatch method118 logger.error("Received unexpected modification event for folder: {}".format(event.src_path))119 return self.put_event(operations.RemoteCreateFolder(context))120 return self.put_event(operations.RemoteUpdateFile(context))121 def put_event(self, event):...
test_gevent.py
Source:test_gevent.py
2from tkshapes.gevent import GEvent, GEventQueue3def test_event_queue_rejects_int():4 with pytest.raises(TypeError):5 q = GEventQueue('test_queue')6 q.put_event(1)7def test_event_queue_rejects_str():8 with pytest.raises(TypeError):9 q = GEventQueue('test_queue')10 q.put_event('foo')11def test_event_id_type():12 g_event_1 = GEvent('Test1', None)13 assert type(g_event_1.event_id) is int14def test_event_id_increment():15 g_event_1 = GEvent('Test1', None)16 g_event_2 = GEvent('Test2', None)17 assert g_event_1.event_id + 1 == g_event_2.event_id18def test_event_type():19 g_event_1 = GEvent('Test1', None)20 assert g_event_1.event_type == 'Test1'21def test_event_queue_name():22 q = GEventQueue('test_queue')23 q_name = q.name24 assert q_name == 'test_queue'25def test_event_queue_empty():26 q = GEventQueue('test_queue')27 assert q.is_empty() is True28def test_event_queue_not_empty():29 q = GEventQueue('test_queue')30 g_event_1 = GEvent('Test1', None)31 q.put_event(g_event_1)32 assert q.is_empty() is False33def test_event_queue_full():34 q = GEventQueue('test_queue', maxsize=1)35 g_event_1 = GEvent('Test1', None)36 q.put_event(g_event_1)37 assert q.is_full() is True38def test_event_queue_not_full():39 q = GEventQueue('test_queue', maxsize=2)40 g_event_1 = GEvent('Test1', None)41 q.put_event(g_event_1)42 assert q.is_full() is False43def test_get_on_empty_queue():44 q = GEventQueue('test_queue')45 assert q.get_event() is None46def test_put_on_full_queue():47 q = GEventQueue('test_queue', maxsize=2)48 g_event_1 = GEvent('Test1', None)49 g_event_2 = GEvent('Test2', None)50 g_event_3 = GEvent('Test3', None)51 g_event_4 = GEvent('Test4', None)52 g_event_5 = GEvent('Test5', None)53 g_event_6 = GEvent('Test6', None)54 assert q.put_event(g_event_1) is True55 assert q.put_event(g_event_2) is True56 assert q.put_event(g_event_3) is False57 assert q.put_event(g_event_4) is False58 assert q.put_event(g_event_5) is False59 q.get_event()60 assert q.put_event(g_event_6) is True61def test_event_queue_size_after_put():62 q = GEventQueue('test_queue')63 g_event_1 = GEvent('Test1', None)64 g_event_2 = GEvent('Test2', None)65 g_event_3 = GEvent('Test3', None)66 g_event_4 = GEvent('Test4', None)67 q.put_event(g_event_1)68 q.put_event(g_event_2)69 q.put_event(g_event_3)70 q.put_event(g_event_4)71 assert q.get_qsize() == 472def test_event_queue_size_after_get():73 q = GEventQueue('test_queue')74 g_event_1 = GEvent('Test1', None)75 g_event_2 = GEvent('Test2', None)76 g_event_3 = GEvent('Test3', None)77 g_event_4 = GEvent('Test4', None)78 q.put_event(g_event_1)79 q.put_event(g_event_2)80 q.put_event(g_event_3)81 q.put_event(g_event_4)82 q.get_event()83 q.get_event()...
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!!