How to use _teardown_session method in Molotov

Best Python code snippet using molotov_python

programmer.py

Source:programmer.py Github

copy

Full Screen

...138 sessionconfig = SessionConfig(self.tool["device_name"])139 sessionconfig.packpath = self.packpath140 self.backend.start_session(sessionconfig)141 self.in_session = True142 def _teardown_session(self):143 # Clean up session144 self.backend.end_session()145 self.backend.disconnect_from_tool()146 self.in_session = False147 def erase_target_device(self):148 """149 Erases target device150 Useful to clean up after provisioning etc when no application is available.151 """152 self.logger.info("Erasing target...")153 try:154 self._setup_session()155 self.backend.erase()156 finally:157 self._teardown_session()158 def program_hexfile(self, filename, memory=MemoryNames.FLASH, erase=True, verify=False):159 """160 Program target with hex file.161 :param filename: Full path to file to program162 :type str:163 :param memory: Memory type to program164 :type memory: str165 :param erase: True to erase before programming166 :type erase: boolean167 :param verify: True to verify after programming168 :type verify: boolean169 :returns: True if programming succeeded170 :rtype: boolean171 """172 self.logger.info("Program hexfile to target:")173 try:174 self._setup_session()175 if erase and memory in [MemoryNames.FLASH]:176 self.logger.info("Erasing %s...", memory)177 self.backend.erase()178 self.logger.info("Programming %s...", memory)179 self.backend.write_hex_to_target(filename)180 if verify:181 self.logger.info("Verifying %s...", memory)182 return self.backend.verify_hex(filename)183 return True184 finally:185 self._teardown_session()186 def program_data(self, data, memory=MemoryNames.FLASH, offset=0, erase=True, verify=False):187 """188 Program target with memory data, assumed to be a byte array.189 :param data: Raw data bytes to program190 :type data: bytearray191 :param memory: Memory type to program192 :type memory: str193 :param offset: First address to program194 :type offset: int195 :param erase: True to erase before programming196 :type erase: boolean197 :param verify: True to verify after programming198 :type verify: boolean199 :returns: True if programming succeeded200 :rtype: boolean201 """202 self.logger.info("Program data to target:")203 try:204 self._setup_session()205 # Attempting to erase other memory types may have unexpected side effects.206 # See also DSG-1408207 if erase and memory in [MemoryNames.FLASH]:208 self.logger.info("Erasing %s...", memory)209 self.backend.erase()210 self.logger.info("Programming %s...", memory)211 self.backend.write_memory(data, memory, offset_byte=offset)212 if verify:213 self.logger.info("Verifying %s...", memory)214 return self.backend.verify_memory(data, memory, offset_byte=offset)215 return True216 finally:217 self._teardown_session()218 def read_data(self, memory=MemoryNames.FLASH, offset=0, size=0):219 """220 Read data from device memory. This function only supports reading a221 single memory, and returns a single bytearray. size=0 means read222 the whole memory.223 :param memory: Memory type to read224 :type memory: str225 :param offset: First address to read226 :type offset: int227 :param size: Number of bytes to read228 :type size: int229 """230 self.logger.info("Read data from target")231 try:232 self._setup_session()233 memories = self.backend.read_memory(memory, offset_byte=offset, numbytes=size)234 return memories[0].data235 finally:236 self._teardown_session()237 def reboot(self):238 """239 Reboot debugger. Note that for IOT kits, this only reboots the debugger, not the target.240 Purpose is to invalidate the cache after the click-me file has been updated.241 """242 # Tool must be connected for reboot to work243 self.backend.connect_to_tool(ToolUsbHidConnection(serialnumber=self.tool["serialnumber"]))244 self.backend.reboot_tool()245 # Disconnect after reboot (not sure if this is required)246 sleep(2)247 self.backend.disconnect_from_tool()248 def reset_target(self, delay=0.0):249 """250 Resets the target device251 :param delay: Number of seconds to delay after reset252 :type delay: float, optional, defaults to 0.5s253 """254 self.logger.info("Reseting target device")255 try:256 self._setup_session()257 # Toggle reset258 self.backend.hold_in_reset()259 sleep(0.1)260 self.backend.release_from_reset()261 sleep(delay)262 finally:...

Full Screen

Full Screen

conftest.py

Source:conftest.py Github

copy

Full Screen

...12 with contextlib.closing(connect()) as conn:13 with conn.cursor() as cursor:14 _create_database(cursor)15 _create_table(cursor)16def _teardown_session():17 with contextlib.closing(connect()) as conn:18 with conn.cursor() as cursor:19 _drop_database(cursor)20 import jpype21 if jpype.isJVMStarted():22 jpype.shutdownJVM()23def _create_database(cursor):24 for q in read_query(os.path.join(BASE_PATH, "sql", "create_database.sql")):25 cursor.execute(q.format(schema=SCHEMA))26def _drop_database(cursor):27 for q in read_query(os.path.join(BASE_PATH, "sql", "drop_database.sql")):28 cursor.execute(q.format(schema=SCHEMA))29def _create_table(cursor):30 location_one_row = "{0}{1}/{2}/".format(ENV.s3_staging_dir, S3_PREFIX, "one_row")...

Full Screen

Full Screen

request.py

Source:request.py Github

copy

Full Screen

1from pyramid.request import Request as _Request2__all__ = ['Request']3def _teardown_session(request):4 # Reset the in-memory SQLAlchemy Session cache after each request.5 request.db.remove()6class Request(_Request):7 DEFAULT_FEATURES = {8 'ssl': True,9 }10 def __init__(self, *args, **kw):11 _Request.__init__(self, *args, **kw)12 self.features = self.DEFAULT_FEATURES.copy()13 self.messages = {}14 # FIXME: Is there a cleaner place to put this?15 from briefmetrics.model.meta import Session16 self.db = Session17 self.add_finished_callback(_teardown_session)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful