How to use timed_operation method in tox

Best Python code snippet using tox_python

timer.py

Source:timer.py Github

copy

Full Screen

...10if six.PY3:11 from time import perf_counter as timer # noqa12__all__ = ['timed_operation', 'IterSpeedCounter', 'Timer']13@contextmanager14def timed_operation(msg, log_start=False):15 """16 Surround a context with a timer.17 Args:18 msg(str): the log to print.19 log_start(bool): whether to print also at the beginning.20 Example:21 .. code-block:: python22 with timed_operation('Good Stuff'):23 time.sleep(1)24 Will print:25 .. code-block:: python26 Good stuff finished, time:1sec.27 """28 assert len(msg)29 if log_start:30 logger.info('Start {} ...'.format(msg))31 start = timer()32 yield33 msg = msg[0].upper() + msg[1:]34 logger.info('{} finished, time:{:.4f} sec.'.format(35 msg, timer() - start))36_TOTAL_TIMER_DATA = defaultdict(StatCounter)...

Full Screen

Full Screen

cwe.py

Source:cwe.py Github

copy

Full Screen

...12 Import the CWE list.13 """14 header("Importing CWE list...")15 # Download the file16 with timed_operation("Downloading {}...".format(MITRE_CWE_URL)):17 resp = requests.get(MITRE_CWE_URL).content18 # Parse weaknesses19 with timed_operation("Parsing cwes..."):20 z = ZipFile(BytesIO(resp))21 raw = z.open(z.namelist()[0]).read()22 obj = untangle.parse(raw.decode("utf-8"))23 weaknesses = obj.Weakness_Catalog.Weaknesses.Weakness24 categories = obj.Weakness_Catalog.Categories.Category25 # Create the objects26 cwes = {}27 with timed_operation("Creating mappings..."):28 for c in weaknesses + categories:29 cwes[c["ID"]] = dict(30 id=get_uuid(),31 cwe_id=f"CWE-{c['ID']}",32 name=c["Name"],33 description=c.Description.cdata34 if hasattr(c, "Description")35 else c.Summary.cdata,36 )37 # Insert the objects in database38 with timed_operation("Inserting CWE..."):39 db.session.bulk_insert_mappings(Cwe, cwes.values())40 db.session.commit()41 info("{} CWE imported.".format(len(cwes)))...

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 tox 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