Best Python code snippet using slash
flash.py
Source:flash.py
...83 modules = [ModuleInfo(*i) for i in modules]84 return FirmwareInfo(major, minor, buildtime, modules)85def write_enable():86 assert_status(tls.cmd(db_write_enable))87def call_cleanups():88 rsp = tls.cmd(b'\x1a')89 err = unpack('<H', rsp[:2])[0]90 if err == 0x0491: # Nothing to commit91 return # don't throw an exception, just ignore92 assert_status(rsp)93def erase_flash(partition: int):94 assert_status(tls.cmd(db_write_enable))95 try:96 assert_status(tls.cmd(pack('<BB', 0x3f, partition)))97 finally:98 call_cleanups()99def read_flash(partition: int, addr: int, size: int) -> bytes:100 cmd = pack('<BBBHLL', 0x40, partition, 1, 0, addr, size)101 rsp = tls.cmd(cmd)102 assert_status(rsp)103 sz, = unpack('<xxLxx', rsp[:8])104 return rsp[8:8 + sz]105def write_flash(partition: int, addr: int, buf: bytes):106 tls.cmd(db_write_enable)107 cmd = pack('<BBBHLL', 0x41, partition, 1, 0, addr, len(buf)) + buf108 try:109 rsp = tls.cmd(cmd)110 assert_status(rsp)111 finally:112 call_cleanups()113def write_flash_all(partition: int, ptr: int, buf: bytes):114 bs = 0x1000115 while len(buf) > 0:116 chunk, buf = buf[:bs], buf[bs:]117 write_flash(partition, ptr, chunk)118 ptr += len(chunk)119def read_flash_all(partition: int, start: int, size: int):120 bs = 0x1000121 blocks = [read_flash(partition, addr, bs) for addr in range(start, start + size, bs)]122 return b''.join(blocks)[:size]123def write_fw_signature(partition: int, signature: bytes):124 rsp = tls.cmd(pack('<BBxH', 0x42, partition, len(signature)) + signature)125 assert_status(rsp)126def read_tls_flash():...
control.py
Source:control.py
...104 action_attempts = queue.Queue(),105 )106 def dump_game_info(self) -> gameinfo.GameInfo:107 return self.game_info108 def call_cleanups(self) -> None:109 """110 If the item in game_info is an object (a.k.a. has the __class__111 attribute) then call its cleanup method.112 """113 for k, v in self.game_info.items():114 if hasattr(v, "__name__"):115 # Mypy doesn't like this call because I'm assuming object116 # has a cleanup method. It isn't guarenteed to, but I can117 # enforce that it does. Ignore the type.118 v.cleanup() # type: ignore119 def cleanup(self) -> None:120 """121 This must be called to give the objects in the game info122 a chance to cleanup.123 """124 self.call_cleanups()125 # I only need to save the npc locations when126 #self.game_info.npc_group = self.npc_group127 # mainmenu won't have noc_group, not sure what to do.128 def startup(self, game_info: gameinfo.GameInfo) -> None:129 raise NotImplementedError130 def update(self, surface: pygame.Surface, dt: int) -> None:...
test_cleanup_manager.py
Source:test_cleanup_manager.py
...6@pytest.mark.parametrize('in_interruption', [True, False])7def test_cleanup_default_scope(cleanup_manager, cleanup, in_failure, in_interruption):8 cleanup_manager.add_cleanup(cleanup)9 assert not cleanup.called10 cleanup_manager.call_cleanups(scope=cleanup_manager.latest_scope, in_failure=in_failure, in_interruption=in_interruption)11 assert cleanup.called == (not in_interruption)12def test_default_scope(cleanup_manager):13 cleanup1 = cleanup_manager.add_cleanup(Checkpoint())14 with cleanup_manager.scope('session'):15 cleanup2 = cleanup_manager.add_cleanup(Checkpoint())16 with cleanup_manager.scope('module'):17 cleanup3 = cleanup_manager.add_cleanup(Checkpoint())18 assert not cleanup3.called19 assert not cleanup2.called20 assert not cleanup1.called21 cleanup_manager.call_cleanups(scope=cleanup_manager.latest_scope, in_failure=False, in_interruption=False)22 assert cleanup1.called23 assert cleanup2.called24 assert cleanup3.called25 assert cleanup3.timestamp < cleanup2.timestamp < cleanup1.timestamp26@pytest.fixture27def cleanup_manager():28 returned = CleanupManager()29 returned.push_scope(None)30 return returned31@pytest.fixture32def cleanup(checkpoint):...
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!!