Best Python code snippet using pytest-benchmark
movement.py
Source:movement.py
...157 if resource_transport.state == STATE_IDLE:158 self.handle_idle(resource_transport)159 continue160 if resource_transport.state == STATE_LOADING:161 self.handle_loading(resource_transport)162 continue163 if resource_transport.state == STATE_UNLOADING:164 self.handle_unloading(resource_transport)165 continue166 if resource_transport.state == STATE_MOVING:167 self.handle_movement(resource_transport)168 continue169 import pdb; pdb.set_trace()170 raise RuntimeError171 def handle_idle(self, resource_transport: ResourceTransport) -> None:172 if not resource_transport.source:173 return174 source = resource_transport.source()175 if not source:176 return177 resources: set = resource_transport.common_route_resources()178 if not source.inventory.available_for_transport(resources):179 return180 if not resource_transport.position() == source.position:181 resource_transport.state_change(STATE_MOVING)182 resource_transport.owner.travel.start(source)183 return184 resource_transport.state_change(STATE_LOADING)185 def handle_loading(self, resource_transport: ResourceTransport) -> None:186 if not resource_transport.source:187 resource_transport.state_change(STATE_IDLE)188 return189 source = resource_transport.source()190 if not source:191 resource_transport.state_change(STATE_IDLE)192 return193 if not resource_transport.position() == source.position:194 resource_transport.state_change(STATE_IDLE)195 return196 resources = resource_transport.common_route_resources()197 routing = source.inventory198 resource = routing.available_for_transport(resources)199 if not resource:...
UI.py
Source:UI.py
1import sys2import serial3import copy4import urwid5import threading6import CubeClass7import moves8import cross9import f2l10import oll11import pll12handle_check_serial = ""13handle_loading = ""14loadcount=015logs = CubeClass.logs16# look_file = tempfile.TemporaryFile()17palette = [18 ("O", "", "", "", "h16", "h166"),19 ("G", "", "", "", "h16", "h02"),20 ("B", "", "", "", "h16", "h04"),21 ("R", "", "", "", "h16", "h01"),22 ("W", "", "", "", "h16", "h15"),23 ("Y", "", "", "", "h16", "h226"),24 ("bg", "", "", "", "h00", "h07"),25 ("hidebg", "", "", "", "h07", "h07"),26 ("header", "", "", "", "h16", "h15"),27 ("logo", "", "", "", "h46", "h00"),28 ("form", "", "", "", "h52", "h39"),29 ("btn_quit", "", "", "", "h15", "h01")30]31ardtopy={"a":moves.right,"b":moves.rightd,"c":moves.right2,32 "d":moves.left,"e":moves.leftd,"f":moves.left2,33 "g":moves.up,"h":moves.upd,"i":moves.up2,34 "j":moves.down,"k":moves.downd,"l":moves.down2,35 "m":moves.front,"n":moves.frontd,"o":moves.front2,36 "p":moves.back,"q":moves.backd,"r":moves.back2,37 "R":"a","R'":"b","R2":"c","L":"d","L'":"e","L2":"f","U":"g","U'":"h","U2":"i","D":"j","D'":"k","D2":"l","F":"m","F'":"n","F2":"o","B":"p","B'":"q","B2":"r"}38def _py_to_ard(itterable):39 ans=""40 for i in itterable:41 if i in ardtopy:42 ans+=ardtopy[i]43 ans+="z\n"44 return ans45cube = CubeClass.cube()46def onclick(key): # {47 if key in ('s', 'S'):48 # logs.write(str(cube_left))49 cube.set_side("WRWOWBRYY", "L")50 # logs.write(str(_left))51 # logs.write("kdfj\n")52 if key in ('u', 'U'):53 moves.up(cube.cubearray)54 cube.get_side_from_array(cube.cubearray)55 cube.update_cube()56 if key in ('k', 'K'):57 pass58def on_submit(button, user_data):59 if (cube.chk_scan.get_state == True):60 cube.txt_scramble.set_edit_text("")61 # code for scanning goes here62 else:63 moves.breakscram(cube.thescramble, cube.cubearray)64 logs.write(str(cube.cubearray))65 cube.get_side_from_array(cube.cubearray)66 cube.update_cube()67 cube.footer1.set_text(["Finding Solution for : ", ("R", cube.thescramble)])68 #logicthread.start()69 ml.draw_screen()70 do_logic()# sets solution71def on_quit(button, user_data):72 raise urwid.ExitMainLoop()73def set_scramble(et, thenew):74 cube.thescramble = thenew75def clear_scramble(et, thenew):76 if (cube.chk_scan.get_state() == False):77 cube.txt_scramble_attr.set_attr_map({None: 'hidebg'})78 cube.footer1.set_text('false')79 else:80 cube.txt_scramble_attr.set_attr_map({'hidebg': None})81 cube.footer1.set_text('true')82def get_full_sol(fullsol):83 fullsol = fullsol.replace("R R'", "")84 fullsol = fullsol.replace("L L'", "")85 fullsol = fullsol.replace("F F'", "")86 fullsol = fullsol.replace("D D'", "")87 fullsol = fullsol.replace("B B'", "")88 fullsol = fullsol.replace("U U'", "")89 fullsol = fullsol.replace("R' R ", "")90 fullsol = fullsol.replace("L' L ", "")91 fullsol = fullsol.replace("F' F ", "")92 fullsol = fullsol.replace("D' D ", "")93 fullsol = fullsol.replace("B' B ", "")94 fullsol = fullsol.replace("U' U ", "")95 fullsol = fullsol.replace("U U ", "U2")96 fullsol = fullsol.replace("F F ", "F2")97 fullsol = fullsol.replace("D D ", "D2")98 fullsol = fullsol.replace("B B ", "B2")99 fullsol = fullsol.replace("L L ", "L2")100 fullsol = fullsol.replace("R R ", "R2")101 fullsol = fullsol.replace("U' U'", "U2")102 fullsol = fullsol.replace("F' F'", "F2")103 fullsol = fullsol.replace("D' D'", "D2")104 fullsol = fullsol.replace("B' B'", "B2")105 fullsol = fullsol.replace("L' L'", "L2")106 fullsol = fullsol.replace("R' R'", "R2")107 fullsol = fullsol.replace("U2 U ", "U'")108 fullsol = fullsol.replace("F2 F ", "F'")109 fullsol = fullsol.replace("D2 D ", "D'")110 fullsol = fullsol.replace("B2 B ", "B'")111 fullsol = fullsol.replace("L2 L ", "L'")112 fullsol = fullsol.replace("R2 R ", "R'")113 fullsol = fullsol.replace("U2 U'", "U")114 fullsol = fullsol.replace("F2 F'", "F")115 fullsol = fullsol.replace("D2 D'", "D")116 fullsol = fullsol.replace("B2 B'", "B")117 fullsol = fullsol.replace("L2 L'", "L")118 fullsol = fullsol.replace("R2 R'", "R")119 fullsol = fullsol.replace("U U2", "U'")120 fullsol = fullsol.replace("F F2", "F'")121 fullsol = fullsol.replace("D D2", "D'")122 fullsol = fullsol.replace("B B2", "B'")123 fullsol = fullsol.replace("L L2", "L'")124 fullsol = fullsol.replace("R R2", "R'")125 fullsol = fullsol.replace("U' U2", "U")126 fullsol = fullsol.replace("F' F2", "F")127 fullsol = fullsol.replace("D' D2", "D")128 fullsol = fullsol.replace("B' B2", "B")129 fullsol = fullsol.replace("L' L2", "L")130 fullsol = fullsol.replace("R' R2", "R")131 return fullsol132def do_logic():133 cubearraycopy=copy.deepcopy(cube.cubearray)134 cr = cross.makecross(cubearraycopy)135 f2 = f2l.dof2l(cubearraycopy)136 ol = oll.solveoll(cubearraycopy)137 pl = pll.solvepll(cubearraycopy)138 cube.set_solution(get_full_sol(cr + " " + f2 + " " + ol + " " + pl))139 kellogs.write(_py_to_ard(cube.thesolution.split(" ")).encode())140 global handle_check_serial141 handle_check_serial=ml.set_alarm_in(1,check_serial,"")142 handle_loading=ml.set_alarm_in(0.5,loadingstatus,"")143def check_serial(theml ,data):144 global handle_check_serial145 currentover = kellogs.read().decode()146 if currentover in ardtopy:147 ardtopy[currentover](cube.cubearray) # move virtualcube148 cube.get_side_from_array(cube.cubearray)149 cube.update_cube()150 cube.position=cube.position+1151 if currentover == 'z':152 theml.remove_alarm(handle_loading)153 cube.footer1.set_text("finito")154 theml.remove_alarm(handle_check_serial)155 else:156 handle_check_serial=theml.set_alarm_in(1,check_serial,"")157def loadingstatus(theml,data):158 global loadcount159 if loadcount>2:160 loadcount=0161 loadcount=loadcount+1162 cube.loading(loadcount)163 theml.draw_screen()164 handle_loading=theml.set_alarm_in(0.5,loadingstatus,"")165def testpopup(data):166 logs.write("VSAUCE::"+data)167 cube.open_pop_up()168if len(sys.argv)!=2:169 valid=False170else:171 valid=True172 port=sys.argv[1]173 kellogs=serial.Serial(port=port,timeout=1)174if valid:175 thescreen = cube.draw_cube()176 #logicthread = threading.Thread(target=do_logic)177 urwid.connect_signal(cube.txt_scramble, 'change', set_scramble)178 urwid.connect_signal(cube.chk_scan, 'change', clear_scramble)179 urwid.connect_signal(cube.btn_quit, 'click', on_quit, "")180 urwid.connect_signal(cube.btn_submit, 'click', on_submit, cube.thescramble)181 #urwid.connect_signal(cube.gf1.contents[1][0],'',testpopup,"michael here")182 ml = urwid.MainLoop(thescreen, palette, unhandled_input=onclick,pop_ups=True)183 ml.screen.set_terminal_properties(colors=256)184 urwid.set_encoding("utf-8")185 ml.run()186else:187 print("::usage::\n"+sys.argv[0]+" [com device]\nWhere:\n[com device] -> Arduino Serial Communication Port\n\n")...
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!!