How to use _format_time method in avocado

Best Python code snippet using avocado_python

time_util.py

Source:time_util.py Github

copy

Full Screen

...6 """clock2() -> (t_user,t_system)7 Similar to clock(), but return a tuple of user/system times.8 """9 return resource.getrusage(resource.RUSAGE_SELF)[:2]10def _format_time(timespan, precision=3):11 """Formats the timespan in a human readable form"""12 if timespan >= 60.0:13 # we have more than a minute, format that in a human readable form14 # Idea from http://snipplr.com/view/5713/15 parts = [("d", 60 * 60 * 24), ("h", 60 * 60), ("min", 60), ("s", 1)]16 time_parts = []17 leftover = timespan18 for suffix, length in parts:19 value = int(leftover / length)20 if value > 0:21 leftover = leftover % length22 time_parts.append(u"%s%s" % (str(value), suffix))23 if leftover < 1:24 break25 return " ".join(time_parts)26 # Unfortunately the unicode 'micro' symbol can cause problems in27 # certain terminals.28 # See bug: https://bugs.launchpad.net/ipython/+bug/34846629 # Try to prevent crashes by being more secure than it needs to30 # E.g. eclipse is able to print a µ, but has no sys.stdout.encoding set.31 units = [u"s", u"ms", u"us", "ns"] # the save value32 if hasattr(sys.stdout, "encoding") and sys.stdout.encoding:33 try:34 u"\xb5".encode(sys.stdout.encoding)35 units = [u"s", u"ms", u"\xb5s", "ns"]36 except:37 pass38 scaling = [1, 1e3, 1e6, 1e9]39 if timespan > 0.0:40 order = min(-int(math.floor(math.log10(timespan)) // 3), 3)41 else:42 order = 343 return u"%.*g %s" % (precision, timespan * scaling[order], units[order])44def timeit(code, glob=globals(), local_ns=locals()):45 wtime = time.time46 # time execution47 wall_st = wtime()48 st = clock2()49 out = eval(code, glob, local_ns)50 end = clock2()51 wall_end = wtime()52 # Compute actual times and report53 wall_time = wall_end - wall_st54 cpu_user = end[0] - st[0]55 cpu_sys = end[1] - st[1]56 cpu_tot = cpu_user + cpu_sys57 # On windows cpu_sys is always zero, so no new information to the next print58 if sys.platform != "win32":59 print("CPU times: user %s, sys: %s, total: %s" % \60 (_format_time(cpu_user),_format_time(cpu_sys),_format_time(cpu_tot)))61 print("Wall time: %s" % _format_time(wall_time))...

Full Screen

Full Screen

test_task.py

Source:test_task.py Github

copy

Full Screen

...30 assert '000%s0000' % d == unformat_time('%s-' % d)31 assert '00000010' == unformat_time('.1')32 assert '00000001' == unformat_time('.01')33@given(integers(min_value=1, max_value=9))34def test__format_time(d):35 assert _format_time('00:00:00.0') == ''36 assert _format_time('00:25:00.0') == '25-'37 assert _format_time('02:00:00.0') == '2--'38 assert _format_time('90:00:00.0') == '90--'39 assert _format_time('00:00:%s0.0' % d) == '%s0' % d40 assert _format_time('00:00:0%s.0' % d) == '%s' % d41 assert _format_time('00:%s0:00.0' % d) == '%s0-' % d42 assert _format_time('00:0%s:00.0' % d) == '%s-' % d43 assert _format_time('00:00:00.002') == '.002'44 assert _format_time('00:00:00.100') == '.1'45 assert _format_time('00:00:00.010') == '.01'46if __name__ == '__main__':47 test_unformat_time()...

Full Screen

Full Screen

03clock.py

Source:03clock.py Github

copy

Full Screen

...22 # Compute actual times and report23 cpu_user = end[0]-st[0]24 cpu_sys = end[1]-st[1]25 cpu_tot = cpu_user+cpu_sys26 print("CPU times: user %s, sys: %s, total: %s" % (_format_time(cpu_user),_format_time(cpu_sys),_format_time(cpu_tot)))27 if tc > tc_min:28 print("Compiler : %s" % _format_time(tc))29 if tp > tp_min:...

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