mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
bpo-33718: regrtest: use format_duration() to display failed tests (GH-7686)
* Enhance also format_duration(): work on integers and rounds towards +infinity (math.ceil). * Write unit tests on format_duration()
This commit is contained in:
parent
dfa9643d29
commit
4ffe9c2b25
3 changed files with 44 additions and 10 deletions
|
|
@ -200,7 +200,7 @@ def run_tests_multiprocess(regrtest):
|
||||||
if (ok not in (CHILD_ERROR, INTERRUPTED)
|
if (ok not in (CHILD_ERROR, INTERRUPTED)
|
||||||
and test_time >= PROGRESS_MIN_TIME
|
and test_time >= PROGRESS_MIN_TIME
|
||||||
and not regrtest.ns.pgo):
|
and not regrtest.ns.pgo):
|
||||||
text += ' (%.0f sec)' % test_time
|
text += ' (%s)' % format_duration(test_time)
|
||||||
elif ok == CHILD_ERROR:
|
elif ok == CHILD_ERROR:
|
||||||
text = '%s (%s)' % (text, test_time)
|
text = '%s (%s)' % (text, test_time)
|
||||||
running = get_running(workers)
|
running = get_running(workers)
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,28 @@
|
||||||
import os.path
|
import os.path
|
||||||
|
import math
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
|
||||||
def format_duration(seconds):
|
def format_duration(seconds):
|
||||||
if seconds < 1.0:
|
ms = math.ceil(seconds * 1e3)
|
||||||
return '%.0f ms' % (seconds * 1e3)
|
seconds, ms = divmod(ms, 1000)
|
||||||
if seconds < 60.0:
|
minutes, seconds = divmod(seconds, 60)
|
||||||
return '%.0f sec' % seconds
|
hours, minutes = divmod(minutes, 60)
|
||||||
|
|
||||||
minutes, seconds = divmod(seconds, 60.0)
|
parts = []
|
||||||
hours, minutes = divmod(minutes, 60.0)
|
|
||||||
if hours:
|
if hours:
|
||||||
return '%.0f hour %.0f min' % (hours, minutes)
|
parts.append('%s hour' % hours)
|
||||||
else:
|
if minutes:
|
||||||
return '%.0f min %.0f sec' % (minutes, seconds)
|
parts.append('%s min' % minutes)
|
||||||
|
if seconds:
|
||||||
|
parts.append('%s sec' % seconds)
|
||||||
|
if ms:
|
||||||
|
parts.append('%s ms' % ms)
|
||||||
|
if not parts:
|
||||||
|
return '0 ms'
|
||||||
|
|
||||||
|
parts = parts[:2]
|
||||||
|
return ' '.join(parts)
|
||||||
|
|
||||||
|
|
||||||
def removepy(names):
|
def removepy(names):
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import threading
|
||||||
import unittest
|
import unittest
|
||||||
from test import libregrtest
|
from test import libregrtest
|
||||||
from test import support
|
from test import support
|
||||||
|
from test.libregrtest import utils
|
||||||
|
|
||||||
|
|
||||||
Py_DEBUG = hasattr(sys, 'getobjects')
|
Py_DEBUG = hasattr(sys, 'getobjects')
|
||||||
|
|
@ -980,5 +981,29 @@ class ArgsTestCase(BaseTestCase):
|
||||||
failed=testname, rerun=testname)
|
failed=testname, rerun=testname)
|
||||||
|
|
||||||
|
|
||||||
|
class TestUtils(unittest.TestCase):
|
||||||
|
def test_format_duration(self):
|
||||||
|
self.assertEqual(utils.format_duration(0),
|
||||||
|
'0 ms')
|
||||||
|
self.assertEqual(utils.format_duration(1e-9),
|
||||||
|
'1 ms')
|
||||||
|
self.assertEqual(utils.format_duration(10e-3),
|
||||||
|
'10 ms')
|
||||||
|
self.assertEqual(utils.format_duration(1.5),
|
||||||
|
'1 sec 500 ms')
|
||||||
|
self.assertEqual(utils.format_duration(1),
|
||||||
|
'1 sec')
|
||||||
|
self.assertEqual(utils.format_duration(2 * 60),
|
||||||
|
'2 min')
|
||||||
|
self.assertEqual(utils.format_duration(2 * 60 + 1),
|
||||||
|
'2 min 1 sec')
|
||||||
|
self.assertEqual(utils.format_duration(3 * 3600),
|
||||||
|
'3 hour')
|
||||||
|
self.assertEqual(utils.format_duration(3 * 3600 + 2 * 60 + 1),
|
||||||
|
'3 hour 2 min')
|
||||||
|
self.assertEqual(utils.format_duration(3 * 3600 + 1),
|
||||||
|
'3 hour 1 sec')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue