Best Python code snippet using fMBT_python
custom_tests.py
Source:custom_tests.py
...13 ( 1, 0, 3, True ),14 ( 2, 0, 3, True ),15 ( 3, 0, 4, True ),16 ( 4, 0, 5, True ), ]17def set_layout( b: Battleship, layout ):18 for x,y,size,vertical in layout:19 b.put_ship( x, y, size, vertical )20async def shoot_layout( b: Battleship, layout ):21 for x,y,size,vertical in layout:22 for i in range(size):23 if vertical:24 await b.round(x, y+i)25 else:26 await b.round(x+i, y)27def check_states_empty( battleship ):28 assert not battleship.finished()29 assert not battleship.won()30 assert not battleship.draw()31 assert not battleship.aborted()32def check_win( b: Battleship ):33 assert b.finished()34 assert b.won()35 assert not b.draw()36 assert not b.aborted()37def check_lost( b: Battleship ):38 assert b.finished()39 assert not b.won()40 assert not b.draw()41 assert not b.aborted()42def check_draw( b: Battleship ):43 assert b.finished()44 assert not b.won()45 assert b.draw()46 assert not b.aborted()47def check_abort( b: Battleship ):48 assert b.finished()49 assert not b.won()50 assert not b.draw()51 assert b.aborted()52async def check_list( b: Battleship, *players ):53 """if absolute is set, check equality of lists."""54 ships = await b.list_games()55 for p in players:56 assert p in ships57class TestConnect_TwoPlayers:58 @staticmethod59 async def launch():60 asyncio.create_task( shipserv.start_server() )61 await asyncio.gather( TestConnect_TwoPlayers.player_1(),62 TestConnect_TwoPlayers.player_2(), )63 @staticmethod64 async def player_1():65 b = Battleship()66 await b.connect(nick="foo")67 check_states_empty( b )68 set_layout( b, get_basic_layout_1() )69 await b.start()70 @staticmethod71 async def player_2():72 b = Battleship()73 await b.connect(nick="bar")74 check_states_empty( b )75 set_layout( b, get_basic_layout_1() )76 lst = await b.list_games()77 assert len(lst) == 178 assert lst[0] == "foo"79 await b.auto()80class TestConnect_FourPlayers:81 @staticmethod82 async def launch():83 asyncio.create_task( shipserv.start_server() )84 await asyncio.gather( TestConnect_FourPlayers.player_1(),85 TestConnect_FourPlayers.player_2(),86 TestConnect_FourPlayers.player_3(),87 TestConnect_FourPlayers.player_4(), )88 @staticmethod89 async def player_1():90 b = Battleship()91 await b.connect(nick="foo")92 check_states_empty( b )93 set_layout( b, get_basic_layout_1() )94 await b.start()95 @staticmethod96 async def player_2():97 b = Battleship()98 await b.connect(nick="bar")99 check_states_empty( b )100 set_layout( b, get_basic_layout_1() )101 lst = await b.list_games()102 assert len(lst) == 1103 assert lst[0] == "foo"104 await b.auto()105 @staticmethod106 async def player_3():107 b = Battleship()108 await b.connect(nick="baz")109 check_states_empty( b )110 set_layout( b, get_basic_layout_1() )111 await asyncio.sleep(0.1)112 await b.start()113 @staticmethod114 async def player_4():115 b = Battleship()116 await b.connect(nick="baaz")117 check_states_empty( b )118 set_layout( b, get_basic_layout_1() )119 await asyncio.sleep(0.3)120 lst = await b.list_games()121 assert len(lst) == 1122 assert lst[0] == "baz"123 await b.join( "baz" )124class TestList_TwoPlayers:125 @staticmethod126 async def launch():127 asyncio.create_task( shipserv.start_server() )128 await asyncio.gather( TestList_TwoPlayers.player_1(),129 TestList_TwoPlayers.player_2(), )130 @staticmethod131 async def player_1():132 b = Battleship()133 await b.connect(nick="foo")134 check_states_empty( b )135 lst = await b.list_games()136 assert len(lst) == 1137 assert lst[0] == "bar"138 set_layout( b, get_basic_layout_1() )139 await b.join( "bar" )140 @staticmethod141 async def player_2():142 b = Battleship()143 await b.connect(nick="bar")144 check_states_empty( b )145 set_layout( b, get_basic_layout_1() )146 await asyncio.sleep(0.1)147 await b.start()148class TestWin_TwoPlayers:149 @staticmethod150 async def launch():151 asyncio.create_task( shipserv.start_server() )152 await asyncio.gather( TestWin_TwoPlayers.player_1(),153 TestWin_TwoPlayers.player_2(), )154 @staticmethod155 async def player_1():156 b = Battleship()157 await b.connect(nick="foo")158 check_states_empty( b )159 set_layout( b, get_basic_layout_1() )160 await b.start()161 check_states_empty( b )162 for _ in range(17):163 await b.round(9, 9)164 check_lost( b )165 @staticmethod166 async def player_2():167 b = Battleship()168 await b.connect(nick="bar")169 check_states_empty( b )170 set_layout( b, get_basic_layout_1() )171 await b.join( "foo" )172 check_states_empty( b )173 await shoot_layout( b, get_basic_layout_1() )174 check_win( b )175class TestWin_StartAuto_TwoPlayers:176 @staticmethod177 async def launch():178 asyncio.create_task( shipserv.start_server() )179 await asyncio.gather( TestWin_StartAuto_TwoPlayers.player_1(),180 TestWin_StartAuto_TwoPlayers.player_2(), )181 @staticmethod182 async def player_1():183 b = Battleship()184 await b.connect(nick="foo")185 check_states_empty( b )186 set_layout( b, get_basic_layout_1() )187 await b.start()188 check_states_empty( b )189 for _ in range(17):190 await b.round(9, 9)191 check_lost( b )192 @staticmethod193 async def player_2():194 b = Battleship()195 await b.connect(nick="bar")196 check_states_empty( b )197 set_layout( b, get_basic_layout_1() )198 await b.auto()199 check_states_empty( b )200 await shoot_layout( b, get_basic_layout_1() )201 check_win( b )202class TestWin_AutoJoin_TwoPlayers:203 @staticmethod204 async def launch():205 asyncio.create_task( shipserv.start_server() )206 await asyncio.gather( TestWin_AutoJoin_TwoPlayers.player_1(),207 TestWin_AutoJoin_TwoPlayers.player_2(), )208 @staticmethod209 async def player_1():210 b = Battleship()211 await b.connect(nick="foo")212 check_states_empty( b )213 set_layout( b, get_basic_layout_1() )214 await b.auto()215 check_states_empty( b )216 for _ in range(17):217 await b.round(9, 9)218 check_lost( b )219 @staticmethod220 async def player_2():221 b = Battleship()222 await b.connect(nick="bar")223 check_states_empty( b )224 set_layout( b, get_basic_layout_1() )225 await b.join( "foo" )226 check_states_empty( b )227 await shoot_layout( b, get_basic_layout_1() )228 check_win( b )229class TestWin_AutoAuto_TwoPlayers:230 @staticmethod231 async def launch():232 asyncio.create_task( shipserv.start_server() )233 await asyncio.gather( TestWin_AutoAuto_TwoPlayers.player_1(),234 TestWin_AutoAuto_TwoPlayers.player_2(), )235 @staticmethod236 async def player_1():237 b = Battleship()238 await b.connect(nick="foo")239 check_states_empty( b )240 set_layout( b, get_basic_layout_1() )241 await b.auto()242 check_states_empty( b )243 for _ in range(17):244 await b.round(9, 9)245 check_lost( b )246 @staticmethod247 async def player_2():248 b = Battleship()249 await b.connect(nick="bar")250 check_states_empty( b )251 set_layout( b, get_basic_layout_1() )252 await b.auto()253 check_states_empty( b )254 await shoot_layout( b, get_basic_layout_1() )255 check_win( b )256class TestDraw_TwoPlayers:257 @staticmethod258 async def launch():259 asyncio.create_task( shipserv.start_server() )260 await asyncio.gather( TestDraw_TwoPlayers.player_1(),261 TestDraw_TwoPlayers.player_2(), )262 @staticmethod263 async def player_1():264 b = Battleship()265 await b.connect(nick="foo")266 check_states_empty( b )267 set_layout( b, get_basic_layout_1() )268 await b.start()269 check_states_empty( b )270 await shoot_layout( b, get_basic_layout_1() )271 check_draw( b )272 @staticmethod273 async def player_2():274 b = Battleship()275 await b.connect(nick="bar")276 check_states_empty( b )277 set_layout( b, get_basic_layout_1() )278 await b.join( "foo" )279 check_states_empty( b )280 await shoot_layout( b, get_basic_layout_1() )281 check_draw( b )282class TestDraw_AutoAuto_TwoPlayers:283 @staticmethod284 async def launch():285 asyncio.create_task( shipserv.start_server() )286 await asyncio.gather( TestDraw_AutoAuto_TwoPlayers.player_1(),287 TestDraw_AutoAuto_TwoPlayers.player_2(), )288 @staticmethod289 async def player_1():290 b = Battleship()291 await b.connect(nick="foo")292 check_states_empty( b )293 set_layout( b, get_basic_layout_1() )294 await b.auto()295 check_states_empty( b )296 await shoot_layout( b, get_basic_layout_1() )297 check_draw( b )298 @staticmethod299 async def player_2():300 b = Battleship()301 await b.connect(nick="bar")302 check_states_empty( b )303 set_layout( b, get_basic_layout_1() )304 await b.auto()305 check_states_empty( b )306 await shoot_layout( b, get_basic_layout_1() )307 check_draw( b )308class TestDraw_AutoJoin_TwoPlayers:309 @staticmethod310 async def launch():311 asyncio.create_task( shipserv.start_server() )312 await asyncio.gather( TestDraw_AutoJoin_TwoPlayers.player_1(),313 TestDraw_AutoJoin_TwoPlayers.player_2(), )314 @staticmethod315 async def player_1():316 b = Battleship()317 await b.connect(nick="foo")318 check_states_empty( b )319 set_layout( b, get_basic_layout_1() )320 await b.auto()321 check_states_empty( b )322 await shoot_layout( b, get_basic_layout_1() )323 check_draw( b )324 @staticmethod325 async def player_2():326 b = Battleship()327 await b.connect(nick="bar")328 check_states_empty( b )329 set_layout( b, get_basic_layout_1() )330 await b.join( "foo" )331 check_states_empty( b )332 await shoot_layout( b, get_basic_layout_1() )333 check_draw( b )334class TestDraw_StartAuto_TwoPlayers:335 @staticmethod336 async def launch():337 asyncio.create_task( shipserv.start_server() )338 await asyncio.gather( TestDraw_StartAuto_TwoPlayers.player_1(),339 TestDraw_StartAuto_TwoPlayers.player_2(), )340 @staticmethod341 async def player_1():342 b = Battleship()343 await b.connect(nick="foo")344 check_states_empty( b )345 set_layout( b, get_basic_layout_1() )346 await b.start()347 check_states_empty( b )348 await shoot_layout( b, get_basic_layout_1() )349 check_draw( b )350 @staticmethod351 async def player_2():352 b = Battleship()353 await b.connect(nick="bar")354 check_states_empty( b )355 set_layout( b, get_basic_layout_1() )356 await b.auto()357 check_states_empty( b )358 await shoot_layout( b, get_basic_layout_1() )359 check_draw( b )360class TestDraw_StartAuto_Restart_TwoPlayers:361 @staticmethod362 async def launch():363 asyncio.create_task( shipserv.start_server() )364 await asyncio.gather( TestDraw_StartAuto_Restart_TwoPlayers.player_1(),365 TestDraw_StartAuto_Restart_TwoPlayers.player_2(), )366 @staticmethod367 async def player_1():368 b = Battleship()369 await b.connect(nick="foo")370 check_states_empty( b )371 set_layout( b, get_basic_layout_1() )372 await b.start()373 check_states_empty( b )374 await shoot_layout( b, get_basic_layout_1() )375 check_draw( b )376 b.restart()377 check_states_empty( b )378 await check_list( b, "bar" )379 set_layout( b, get_basic_layout_2() )380 await b.join( "bar" )381 await shoot_layout( b, get_basic_layout_2() )382 check_draw( b )383 @staticmethod384 async def player_2():385 b = Battleship()386 await b.connect(nick="bar")387 check_states_empty( b )388 set_layout( b, get_basic_layout_1() )389 await b.auto()390 check_states_empty( b )391 await shoot_layout( b, get_basic_layout_1() )392 check_draw( b )393 b.restart()394 check_states_empty( b )395 set_layout( b, get_basic_layout_2() )396 await b.start()397 await shoot_layout( b, get_basic_layout_2() )398 check_draw( b )399class TestWin_StartAuto_Restart_TwoPlayers:400 @staticmethod401 async def launch():402 asyncio.create_task( shipserv.start_server() )403 await asyncio.gather( TestWin_StartAuto_Restart_TwoPlayers.player_1(),404 TestWin_StartAuto_Restart_TwoPlayers.player_2(), )405 @staticmethod406 async def player_1():407 b = Battleship()408 await b.connect(nick="foo")409 check_states_empty( b )410 set_layout( b, get_basic_layout_1() )411 await b.start()412 check_states_empty( b )413 await shoot_layout( b, get_basic_layout_1() )414 check_win( b )415 b.restart()416 check_states_empty( b )417 await check_list( b, "bar" )418 set_layout( b, get_basic_layout_2() )419 await b.join( "bar" )420 for _ in range(17):421 await b.round(9, 9)422 check_lost( b )423 @staticmethod424 async def player_2():425 b = Battleship()426 await b.connect(nick="bar")427 check_states_empty( b )428 set_layout( b, get_basic_layout_1() )429 await b.auto()430 check_states_empty( b )431 for _ in range(17):432 await b.round(9, 9)433 check_lost( b )434 b.restart()435 check_states_empty( b )436 set_layout( b, get_basic_layout_2() )437 await b.start()438 await shoot_layout( b, get_basic_layout_2() )439 check_win( b )440class TestWin_AutoJoin_Restart_TwoPlayers:441 @staticmethod442 async def launch():443 asyncio.create_task( shipserv.start_server() )444 await asyncio.gather( TestWin_AutoJoin_Restart_TwoPlayers.player_1(),445 TestWin_AutoJoin_Restart_TwoPlayers.player_2(), )446 @staticmethod447 async def player_1():448 b = Battleship()449 await b.connect(nick="foo")450 check_states_empty( b )451 set_layout( b, get_basic_layout_1() )452 await b.auto()453 check_states_empty( b )454 await shoot_layout( b, get_basic_layout_1() )455 check_win( b )456 b.restart()457 check_states_empty( b )458 await check_list( b, "bar" )459 set_layout( b, get_basic_layout_2() )460 await asyncio.sleep(0.1)461 await b.join( "bar" )462 for _ in range(17):463 await b.round(9, 9)464 check_lost( b )465 @staticmethod466 async def player_2():467 b = Battleship()468 await b.connect(nick="bar")469 check_states_empty( b )470 set_layout( b, get_basic_layout_1() )471 await asyncio.sleep(0.1)472 await b.join("foo")473 check_states_empty( b )474 for _ in range(17):475 await b.round(9, 9)476 check_lost( b )477 b.restart()478 check_states_empty( b )479 set_layout( b, get_basic_layout_2() )480 await b.auto()481 await shoot_layout( b, get_basic_layout_2() )482 check_win( b )483class TestWin_AutoAuto_Restart_TwoPlayers:484 @staticmethod485 async def launch():486 asyncio.create_task( shipserv.start_server() )487 await asyncio.gather( TestWin_AutoAuto_Restart_TwoPlayers.player_1(),488 TestWin_AutoAuto_Restart_TwoPlayers.player_2(), )489 @staticmethod490 async def player_1():491 b = Battleship()492 await b.connect(nick="foo")493 check_states_empty( b )494 set_layout( b, get_basic_layout_1() )495 await b.auto()496 check_states_empty( b )497 await shoot_layout( b, get_basic_layout_1() )498 check_win( b )499 b.restart()500 check_states_empty( b )501 await check_list( b, "bar" )502 set_layout( b, get_basic_layout_2() )503 await asyncio.sleep(0.1)504 await b.auto()505 for _ in range(17):506 await b.round(9, 9)507 check_lost( b )508 @staticmethod509 async def player_2():510 b = Battleship()511 await b.connect(nick="bar")512 check_states_empty( b )513 set_layout( b, get_basic_layout_1() )514 await asyncio.sleep(0.1)515 await b.auto()516 check_states_empty( b )517 for _ in range(17):518 await b.round(9, 9)519 check_lost( b )520 b.restart()521 check_states_empty( b )522 set_layout( b, get_basic_layout_2() )523 await b.auto()524 await shoot_layout( b, get_basic_layout_2() )525 check_win( b )526class TestAbort_HashMismatch_StartJoin_GoodBad_TwoPlayers:527 @staticmethod528 async def launch():529 asyncio.create_task( shipserv.start_server() )530 await asyncio.gather( TestAbort_HashMismatch_StartJoin_GoodBad_TwoPlayers.player_1(),531 TestAbort_HashMismatch_StartJoin_GoodBad_TwoPlayers.player_2(), )532 @staticmethod533 async def player_1():534 b = Battleship()535 await b.connect(nick="foo")536 check_states_empty( b )537 set_layout( b, get_basic_layout_1() )538 b._salt = "invalid_salt"539 await b.start()540 check_states_empty( b )541 await shoot_layout( b, get_basic_layout_1() )542 check_abort( b )543 @staticmethod544 async def player_2():545 b = Battleship()546 await b.connect(nick="bar")547 check_states_empty( b )548 set_layout( b, get_basic_layout_1() )549 await asyncio.sleep(0.1)550 await b.join("foo")551 check_states_empty( b )552 for i in range(17):553 await b.round(9, 9)554 check_abort( b )555class TestAbort_HashMismatch_StartJoin_BadGood_TwoPlayers:556 @staticmethod557 async def launch():558 asyncio.create_task( shipserv.start_server() )559 await asyncio.gather( TestAbort_HashMismatch_StartJoin_BadGood_TwoPlayers.player_1(),560 TestAbort_HashMismatch_StartJoin_BadGood_TwoPlayers.player_2(), )561 @staticmethod562 async def player_1():563 b = Battleship()564 await b.connect(nick="foo")565 check_states_empty( b )566 set_layout( b, get_basic_layout_1() )567 await b.start()568 check_states_empty( b )569 await shoot_layout( b, get_basic_layout_1() )570 check_abort( b )571 @staticmethod572 async def player_2():573 b = Battleship()574 await b.connect(nick="bar")575 check_states_empty( b )576 set_layout( b, get_basic_layout_1() )577 await asyncio.sleep(0.1)578 b._salt = "invalid_salt"579 await b.join("foo")580 check_states_empty( b )581 for i in range(17):582 await b.round(9, 9)583 check_abort( b )584class TestAbort_HashMismatch_StartJoin_BadBad_Restart_TwoPlayers:585 @staticmethod586 async def launch():587 asyncio.create_task( shipserv.start_server() )588 await asyncio.gather( TestAbort_HashMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_1(),589 TestAbort_HashMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_2(), )590 @staticmethod591 async def player_1():592 b = Battleship()593 await b.connect(nick="foo")594 check_states_empty( b )595 set_layout( b, get_basic_layout_1() )596 b._salt = "invalid_salt2"597 await b.start()598 check_states_empty( b )599 await shoot_layout( b, get_basic_layout_1() )600 check_abort( b )601 b.restart()602 check_states_empty( b )603 await check_list( b, "bar" )604 set_layout( b, get_basic_layout_2() )605 await asyncio.sleep(0.1)606 b._server_salt = "invalid_hash"607 await b.auto()608 for _ in range(17):609 await b.round(9, 9)610 check_abort( b )611 @staticmethod612 async def player_2():613 b = Battleship()614 await b.connect(nick="bar")615 check_states_empty( b )616 set_layout( b, get_basic_layout_1() )617 await asyncio.sleep(0.1)618 b._salt = "invalid_salt1"619 await b.join("foo")620 check_states_empty( b )621 for i in range(17):622 await b.round(9, 9)623 check_abort( b )624 b.restart()625 check_states_empty( b )626 set_layout( b, get_basic_layout_2() )627 b._server_salt = "invalid_hash"628 await b.auto()629 await shoot_layout( b, get_basic_layout_2() )630 check_abort( b )631class TestAbort_BoardMismatch_StartJoin_BadBad_Restart_TwoPlayers:632 @staticmethod633 async def launch():634 asyncio.create_task( shipserv.start_server() )635 await asyncio.gather( TestAbort_BoardMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_1(),636 TestAbort_BoardMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_2(), )637 @staticmethod638 async def player_1():639 b = Battleship()640 await b.connect(nick="foo")641 check_states_empty( b )642 set_layout( b, get_basic_layout_1() )643 b._ship_layout = get_basic_layout_2()644 await b.start()645 check_states_empty( b )646 await shoot_layout( b, get_basic_layout_1() )647 check_abort( b )648 b.restart()649 check_states_empty( b )650 await check_list( b, "bar" )651 set_layout( b, get_basic_layout_2() )652 await asyncio.sleep(0.1)653 b._ship_layout = get_basic_layout_1()654 await b.auto()655 for _ in range(17):656 await b.round(9, 9)657 check_abort( b )658 @staticmethod659 async def player_2():660 b = Battleship()661 await b.connect(nick="bar")662 check_states_empty( b )663 set_layout( b, get_basic_layout_1() )664 await asyncio.sleep(0.1)665 b._ship_layout = get_basic_layout_2()666 await b.join("foo")667 check_states_empty( b )668 for i in range(17):669 await b.round(9, 9)670 check_abort( b )671 b.restart()672 check_states_empty( b )673 set_layout( b, get_basic_layout_2() )674 b._ship_layout = get_basic_layout_1()675 await b.auto()676 await shoot_layout( b, get_basic_layout_2() )677 check_abort( b )678class TestAbort_HashBoardMismatch_StartJoin_BadBad_Restart_TwoPlayers:679 @staticmethod680 async def launch():681 asyncio.create_task( shipserv.start_server() )682 await asyncio.gather( TestAbort_HashBoardMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_1(),683 TestAbort_HashBoardMismatch_StartJoin_BadBad_Restart_TwoPlayers.player_2(), )684 @staticmethod685 async def player_1():686 b = Battleship()687 await b.connect(nick="foo")688 check_states_empty( b )689 set_layout( b, get_basic_layout_1() )690 b._ship_layout = get_basic_layout_2()691 b._salt = "invalid_salt"692 await b.start()693 check_states_empty( b )694 await shoot_layout( b, get_basic_layout_1() )695 check_abort( b )696 b.restart()697 check_states_empty( b )698 await check_list( b, "bar" )699 set_layout( b, get_basic_layout_2() )700 await asyncio.sleep(0.1)701 b._ship_layout = get_basic_layout_1()702 b._salt = "invalid_salt"703 await b.auto()704 for _ in range(17):705 await b.round(9, 9)706 check_abort( b )707 @staticmethod708 async def player_2():709 b = Battleship()710 await b.connect(nick="bar")711 check_states_empty( b )712 set_layout( b, get_basic_layout_1() )713 await asyncio.sleep(0.1)714 b._ship_layout = get_basic_layout_2()715 b._salt = "invalid_salt"716 await b.join("foo")717 check_states_empty( b )718 for i in range(17):719 await b.round(9, 9)720 check_abort( b )721 b.restart()722 check_states_empty( b )723 set_layout( b, get_basic_layout_2() )724 b._ship_layout = get_basic_layout_1()725 b._salt = "invalid_salt"726 await b.auto()727 await shoot_layout( b, get_basic_layout_2() )728 check_abort( b )729class TestList_ActiveGames_Increase_TwoPlayers:730 @staticmethod731 async def launch():732 asyncio.create_task( shipserv.start_server() )733 await asyncio.gather( TestList_ActiveGames_Increase_TwoPlayers.add_active_games(),734 TestList_ActiveGames_Increase_TwoPlayers.join_active_games(),735 TestList_ActiveGames_Increase_TwoPlayers.waiter(), )736 @staticmethod737 async def add_active_games():738 for i in range(10):739 b = Battleship()740 await b.connect(nick=f"host{i}")741 set_layout( b, get_basic_layout_1() )742 await b.start()743 print(f"game {i} started")744 check_states_empty( b )745 await asyncio.sleep(0.1)746 @staticmethod747 async def join_active_games():748 for i in range(10):749 b2 = Battleship()750 await b2.connect(nick=f"joiner{i}")751 set_layout( b2, get_basic_layout_1() )752 await b2.join(f"host{i}")753 check_states_empty( b2 )754 print(f"game {i} joined")755 await asyncio.sleep(0.1)756 await asyncio.sleep(1)757 raise TimeoutError #test ended758 @staticmethod759 async def waiter():760 b = Battleship()761 await b.connect(nick="infiniteLister")762 set_layout( b, get_basic_layout_1() )763 lst = await b.list_games()764 assert False, f"listed {lst}, should not list anything and wait forever"765class TestList_ActiveGames_IncreaseDecrease_TwoPlayers:766 @staticmethod767 async def launch():768 TestList_ActiveGames_IncreaseDecrease_TwoPlayers.queue = asyncio.Queue(maxsize=1)769 TestList_ActiveGames_IncreaseDecrease_TwoPlayers.sem = asyncio.Semaphore(0)770 771 asyncio.create_task( shipserv.start_server() )772 await asyncio.gather( TestList_ActiveGames_IncreaseDecrease_TwoPlayers.add_active_games(),773 TestList_ActiveGames_IncreaseDecrease_TwoPlayers.join_active_games(),774 TestList_ActiveGames_IncreaseDecrease_TwoPlayers.waiter(), )775 @staticmethod776 async def add_active_games():777 ships = []778 for i in range(10):779 b = Battleship()780 ships.append( b )781 await b.connect(nick=f"host{i}")782 set_layout( b, get_basic_layout_1() )783 await b.start()784 print(f"game {i} started")785 check_states_empty( b )786 await asyncio.sleep(0.1)787 # TestList_ActiveGames_TwoPlayers.queue.add(1)788 for s in ships:789 await shoot_layout( s , get_basic_layout_1() )790 check_draw( s )791 await asyncio.sleep(0.1)792 @staticmethod793 async def join_active_games():794 ships = []795 for i in range(10):796 b2 = Battleship()797 ships.append( b2 )798 await b2.connect(nick=f"joiner{i}")799 set_layout( b2, get_basic_layout_1() )800 await b2.join(f"host{i}")801 check_states_empty( b2 )802 print(f"game {i} joined")803 await asyncio.sleep(0.1)804 # await TestList_ActiveGames_TwoPlayers.queue.get()805 # sem.release()806 for s in ships:807 await shoot_layout( s, get_basic_layout_1() )808 check_draw( s )809 await asyncio.sleep(0.1)810 # await asyncio.sleep(1)811 raise TimeoutError #test ended812 @staticmethod813 async def waiter():814 await asyncio.sleep(0.1)815 b = Battleship()816 await b.connect(nick="infiniteLister")817 set_layout( b, get_basic_layout_1() )818 # await TestList_ActiveGames_TwoPlayers.sem.acquire()819 lst = await b.list_games()820 assert False, f"listed {lst}, should not list anything and wait forever"821class TestList_WaitingGames_Increase_TwoPlayers:822 @staticmethod823 async def launch():824 asyncio.create_task( shipserv.start_server() )825 await asyncio.gather( TestList_WaitingGames_Increase_TwoPlayers.add_active_games(),826 TestList_WaitingGames_Increase_TwoPlayers.join_active_games(),827 TestList_WaitingGames_Increase_TwoPlayers.add_additional_active_games(),828 TestList_WaitingGames_Increase_TwoPlayers.waiter(),)829 @staticmethod830 async def add_active_games():831 for i in range(10):832 b = Battleship()833 await b.connect(nick=f"host{i}")834 set_layout( b, get_basic_layout_1() )835 await b.start()836 print(f"game {i} started")837 check_states_empty( b )838 await asyncio.sleep(0.1)839 @staticmethod840 async def join_active_games():841 for i in range(10):842 b2 = Battleship()843 await b2.connect(nick=f"joiner{i}")844 set_layout( b2, get_basic_layout_1() )845 await b2.join(f"host{i}")846 check_states_empty( b2 )847 print(f"game {i} joined")848 await asyncio.sleep(0.1)849 @staticmethod850 async def add_additional_active_games():851 for i in range(10):852 b = Battleship()853 await b.connect(nick=f"additional{i}")854 set_layout( b, get_basic_layout_1() )855 await b.start()856 print(f"additional game {i} started")857 check_states_empty( b )858 await asyncio.sleep(0.1)859 @staticmethod860 async def waiter():861 b = Battleship()862 await b.connect(nick="infiniteLister")863 set_layout( b, get_basic_layout_1() )864 for i in range(1,11):865 print("listing games")866 lst = await b.list_games()867 assert len(lst) == i, f"expected lenght {i} got {lst}"868class Test_Aisa2:869 @staticmethod870 async def launch():871 asyncio.create_task( shipserv.start_server() )872 await asyncio.gather( Test_Aisa2.player_1(),873 Test_Aisa2.player_2(), )874 @staticmethod875 async def player_1():876 b = Battleship()877 b.put_ship( 0, 0, 5, True )...
sublime_text.py
Source:sublime_text.py
1import re2from xkeysnail.transform import *3from .context import Context4define_keymap(re.compile("Sublime_text", re.IGNORECASE),{5 K("Super-Space"): K("C-Space"), # Basic code completion6 K("C-Super-up"): K("M-o"), # Switch file7 K("Super-RC-f"): K("f11"), # toggle_full_screen8 K("C-M-v"): [K("C-k"), K("C-v")], # paste_from_history9 K("C-up"): pass_through_key, # cancel scroll_lines up10 K("C-M-up"): K("C-up"), # scroll_lines up11 K("C-down"): pass_through_key, # cancel scroll_lines down12 K("C-M-down"): K("C-down"), # scroll_lines down13 K("Super-Shift-up"): K("M-Shift-up"), # multi-cursor up14 K("Super-Shift-down"): K("M-Shift-down"), # multi-cursor down15 K("C-PAGE_DOWN"): pass_through_key, # cancel next_view16 K("C-PAGE_UP"): pass_through_key, # cancel prev_view17 K("C-Shift-left_brace"): K("C-PAGE_DOWN"), # next_view18 K("C-Shift-right_brace"): K("C-PAGE_UP"), # prev_view19 K("C-M-right"): K("C-PAGE_DOWN"), # next_view20 K("C-M-left"): K("C-PAGE_UP"), # prev_view21 K("insert"): pass_through_key, # cancel toggle_overwrite22 K("C-M-o"): K("insert"), # toggle_overwrite23 K("M-c"): pass_through_key, # cancel toggle_case_sensitive24 K("C-M-c"): K("M-c"), # toggle_case_sensitive25 K("C-h"): pass_through_key, # cancel replace26 K("C-M-f"): K("C-h"), # replace27 K("C-Shift-h"): pass_through_key, # cancel replace_next28 K("C-M-e"): K("C-Shift-h"), # replace_next29 K("f3"): pass_through_key, # cancel find_next30 K("C-g"): K("f3"), # find_next31 K("Shift-f3"): pass_through_key, # cancel find_prev32 K("C-Shift-g"): K("Shift-f3"), # find_prev33 K("C-f3"): pass_through_key, # cancel find_under34 K("Super-M-g"): K("C-f3"), # find_under35 K("C-Shift-f3"): pass_through_key, # cancel find_under_prev36 K("Super-M-Shift-g"): K("C-Shift-f3"), # find_under_prev37 K("M-f3"): pass_through_key, # Default - cancel find_all_under38 # K("M-Refresh"): pass_through_key, # Chromebook - cancel find_all_under39 # K("M-C-g"): K("M-Refresh"), # Chromebook - find_all_under40 K("Super-C-g"): K("M-f3"), # Default - find_all_under41 K("C-Shift-up"): pass_through_key, # cancel swap_line_up42 K("Super-M-up"): K("C-Shift-up"), # swap_line_up43 K("C-Shift-down"): pass_through_key, # cancel swap_line_down44 K("Super-M-down"): K("C-Shift-down"), # swap_line_down45 K("C-Pause"): pass_through_key, # cancel cancel_build46 K("Super-c"): K("C-Pause"), # cancel_build47 K("f9"): pass_through_key, # cancel sort_lines case_s false48 K("f5"): K("f9"), # sort_lines case_s false49 K("Super-f9"): pass_through_key, # cancel sort_lines case_s true50 K("Super-f5"): K("Super-f9"), # sort_lines case_s true51 K("M-Shift-Key_1"): pass_through_key, # cancel set_layout52 K("C-M-Key_1"): K("M-Shift-Key_1"), # set_layout53 K("M-Shift-Key_2"): pass_through_key, # cancel set_layout54 K("C-M-Key_2"): K("M-Shift-Key_2"), # set_layout55 K("M-Shift-Key_3"): pass_through_key, # cancel set_layout56 K("C-M-Key_3"): K("M-Shift-Key_3"), # set_layout57 K("M-Shift-Key_4"): pass_through_key, # cancel set_layout58 K("C-M-Key_4"): K("M-Shift-Key_4"), # set_layout59 K("M-Shift-Key_8"): pass_through_key, # cancel set_layout60 K("C-M-Shift-Key_2"): K("M-Shift-Key_8"), # set_layout61 K("M-Shift-Key_9"): pass_through_key, # cancel set_layout62 K("C-M-Shift-Key_3"): K("M-Shift-Key_9"), # set_layout63 K("M-Shift-Key_5"): pass_through_key, # cancel set_layout64 K("C-M-Shift-Key_5"): K("M-Shift-Key_5"), # set_layout65 # K(""): pass_through_key, # cancel66 # K(""): K(""), #...
dev_utils.py
Source:dev_utils.py
1import inspect2import sys3import traceback4from ast import literal_eval5from PyQt5.QtWidgets import *6from mne_pipeline_hd.gui import parameter_widgets7from mne_pipeline_hd.gui.base_widgets import SimpleDict8from mne_pipeline_hd.gui.parameter_widgets import Param9from mne_pipeline_hd.tests.test_param_guis import gui_kwargs, parameters10class ParamGuis(QWidget):11 def __init__(self):12 super().__init__()13 self.gui_dict = dict()14 self.init_ui()15 def init_ui(self):16 test_layout = QVBoxLayout()17 grid_layout = QGridLayout()18 max_cols = 419 param_names = list(parameters.keys())20 for idx, gui_name in enumerate(param_names):21 gui_class = getattr(parameter_widgets, gui_name)22 gui_parameters = list(inspect.signature(gui_class).parameters) + \23 list(inspect.signature(Param).parameters)24 kwargs = {key: value for key, value in gui_kwargs.items()25 if key in gui_parameters}26 gui = gui_class(data=parameters, name=gui_name, **kwargs)27 grid_layout.addWidget(gui, idx // max_cols, idx % max_cols)28 self.gui_dict[gui_name] = gui29 test_layout.addLayout(grid_layout)30 set_layout = QHBoxLayout()31 self.gui_cmbx = QComboBox()32 self.gui_cmbx.addItems(self.gui_dict.keys())33 set_layout.addWidget(self.gui_cmbx)34 self.set_le = QLineEdit()35 set_layout.addWidget(self.set_le)36 set_bt = QPushButton('Set')37 set_bt.clicked.connect(self.set_param)38 set_layout.addWidget(set_bt)39 show_bt = QPushButton('Show Parameters')40 show_bt.clicked.connect(self.show_parameters)41 set_layout.addWidget(show_bt)42 test_layout.addLayout(set_layout)43 self.setLayout(test_layout)44 def set_param(self):45 try:46 current_gui = self.gui_cmbx.currentText()47 try:48 value = literal_eval(self.set_le.text())49 except (SyntaxError, ValueError):50 value = self.set_le.text()51 parameters[current_gui] = value52 p_gui = self.gui_dict[current_gui]53 p_gui.read_param()54 p_gui._set_param()55 except:56 print(traceback.format_exc())57 def show_parameters(self):58 dlg = QDialog(self)59 layout = QVBoxLayout()60 layout.addWidget(SimpleDict(parameters))61 dlg.setLayout(layout)62 dlg.open()63if __name__ == '__main__':64 app = QApplication.instance() or QApplication(sys.argv)65 test_widget = ParamGuis()66 test_widget.show()...
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!!