diff options
author | Robert Collins <rbtcollins@hp.com> | 2015-03-17 20:54:50 (GMT) |
---|---|---|
committer | Robert Collins <rbtcollins@hp.com> | 2015-03-17 20:54:50 (GMT) |
commit | 302dbc6792895de98ab14b382e7a35f512396ac7 (patch) | |
tree | 9c83183ef5b8dc84fa2d29b15b6ef3e3beb726c3 /Lib/test | |
parent | f024d263b4af789af0eb3727417bbeec582f69eb (diff) | |
download | cpython-302dbc6792895de98ab14b382e7a35f512396ac7.zip cpython-302dbc6792895de98ab14b382e7a35f512396ac7.tar.gz cpython-302dbc6792895de98ab14b382e7a35f512396ac7.tar.bz2 |
Issue #18983: Allow selection of output units in timeit.
This allows manual selection of a specific unit such as usecs rather than the
use of a heuristic. This is intended to aid machine processing of timeit
output.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_timeit.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_timeit.py b/Lib/test/test_timeit.py index 267d2c8..eebad18 100644 --- a/Lib/test/test_timeit.py +++ b/Lib/test/test_timeit.py @@ -312,6 +312,26 @@ class TestTimeit(unittest.TestCase): 10000 loops, best of 3: 50 usec per loop """)) + def test_main_with_time_unit(self): + unit_sec = self.run_main(seconds_per_increment=0.002, + switches=['-u', 'sec']) + self.assertEqual(unit_sec, + "1000 loops, best of 3: 0.002 sec per loop\n") + unit_msec = self.run_main(seconds_per_increment=0.002, + switches=['-u', 'msec']) + self.assertEqual(unit_msec, + "1000 loops, best of 3: 2 msec per loop\n") + unit_usec = self.run_main(seconds_per_increment=0.002, + switches=['-u', 'usec']) + self.assertEqual(unit_usec, + "1000 loops, best of 3: 2e+03 usec per loop\n") + # Test invalid unit input + with captured_stderr() as error_stringio: + invalid = self.run_main(seconds_per_increment=0.002, + switches=['-u', 'parsec']) + self.assertEqual(error_stringio.getvalue(), + "Unrecognized unit. Please select usec, msec, or sec.\n") + def test_main_exception(self): with captured_stderr() as error_stringio: s = self.run_main(switches=['1/0']) |