mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
bpo-33718: regrtest: enhance "running:" formatting (GH-7292)
* "running:" progress: Format number of seconds as hours and minutes * format_duration(): count also minutes as hours * Create Lib/test/libregrtest/utils.py
This commit is contained in:
parent
ef634b5b26
commit
7ad16eb51c
3 changed files with 51 additions and 43 deletions
|
|
@ -8,7 +8,6 @@ import re
|
|||
import sys
|
||||
import sysconfig
|
||||
import tempfile
|
||||
import textwrap
|
||||
import time
|
||||
import unittest
|
||||
from test.libregrtest.cmdline import _parse_args
|
||||
|
|
@ -18,6 +17,7 @@ from test.libregrtest.runtest import (
|
|||
INTERRUPTED, CHILD_ERROR,
|
||||
PROGRESS_MIN_TIME, format_test_result)
|
||||
from test.libregrtest.setup import setup_tests
|
||||
from test.libregrtest.utils import removepy, count, format_duration, printlist
|
||||
from test import support
|
||||
try:
|
||||
import gc
|
||||
|
|
@ -41,16 +41,6 @@ else:
|
|||
TEMPDIR = os.path.abspath(TEMPDIR)
|
||||
|
||||
|
||||
def format_duration(seconds):
|
||||
if seconds < 1.0:
|
||||
return '%.0f ms' % (seconds * 1e3)
|
||||
if seconds < 60.0:
|
||||
return '%.0f sec' % seconds
|
||||
|
||||
minutes, seconds = divmod(seconds, 60.0)
|
||||
return '%.0f min %.0f sec' % (minutes, seconds)
|
||||
|
||||
|
||||
class Regrtest:
|
||||
"""Execute a test suite.
|
||||
|
||||
|
|
@ -567,37 +557,6 @@ class Regrtest:
|
|||
sys.exit(0)
|
||||
|
||||
|
||||
def removepy(names):
|
||||
if not names:
|
||||
return
|
||||
for idx, name in enumerate(names):
|
||||
basename, ext = os.path.splitext(name)
|
||||
if ext == '.py':
|
||||
names[idx] = basename
|
||||
|
||||
|
||||
def count(n, word):
|
||||
if n == 1:
|
||||
return "%d %s" % (n, word)
|
||||
else:
|
||||
return "%d %ss" % (n, word)
|
||||
|
||||
|
||||
def printlist(x, width=70, indent=4, file=None):
|
||||
"""Print the elements of iterable x to stdout.
|
||||
|
||||
Optional arg width (default 70) is the maximum line length.
|
||||
Optional arg indent (default 4) is the number of blanks with which to
|
||||
begin each line.
|
||||
"""
|
||||
|
||||
blanks = ' ' * indent
|
||||
# Print the sorted list: 'x' may be a '--random' list or a set()
|
||||
print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width,
|
||||
initial_indent=blanks, subsequent_indent=blanks),
|
||||
file=file)
|
||||
|
||||
|
||||
def main(tests=None, **kwargs):
|
||||
"""Run the Python suite."""
|
||||
Regrtest().main(tests=tests, **kwargs)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ from test.libregrtest.runtest import (
|
|||
runtest, INTERRUPTED, CHILD_ERROR, PROGRESS_MIN_TIME,
|
||||
format_test_result)
|
||||
from test.libregrtest.setup import setup_tests
|
||||
from test.libregrtest.utils import format_duration
|
||||
|
||||
|
||||
# Display the running tests if nothing happened last N seconds
|
||||
|
|
@ -167,7 +168,8 @@ def run_tests_multiprocess(regrtest):
|
|||
continue
|
||||
dt = time.monotonic() - worker.start_time
|
||||
if dt >= PROGRESS_MIN_TIME:
|
||||
running.append('%s (%.0f sec)' % (current_test, dt))
|
||||
text = '%s (%s)' % (current_test, format_duration(dt))
|
||||
running.append(text)
|
||||
return running
|
||||
|
||||
finished = 0
|
||||
|
|
|
|||
47
Lib/test/libregrtest/utils.py
Normal file
47
Lib/test/libregrtest/utils.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import os.path
|
||||
import textwrap
|
||||
|
||||
|
||||
def format_duration(seconds):
|
||||
if seconds < 1.0:
|
||||
return '%.0f ms' % (seconds * 1e3)
|
||||
if seconds < 60.0:
|
||||
return '%.0f sec' % seconds
|
||||
|
||||
minutes, seconds = divmod(seconds, 60.0)
|
||||
hours, minutes = divmod(minutes, 60.0)
|
||||
if hours:
|
||||
return '%.0f hour %.0f min' % (hours, minutes)
|
||||
else:
|
||||
return '%.0f min %.0f sec' % (minutes, seconds)
|
||||
|
||||
|
||||
def removepy(names):
|
||||
if not names:
|
||||
return
|
||||
for idx, name in enumerate(names):
|
||||
basename, ext = os.path.splitext(name)
|
||||
if ext == '.py':
|
||||
names[idx] = basename
|
||||
|
||||
|
||||
def count(n, word):
|
||||
if n == 1:
|
||||
return "%d %s" % (n, word)
|
||||
else:
|
||||
return "%d %ss" % (n, word)
|
||||
|
||||
|
||||
def printlist(x, width=70, indent=4, file=None):
|
||||
"""Print the elements of iterable x to stdout.
|
||||
|
||||
Optional arg width (default 70) is the maximum line length.
|
||||
Optional arg indent (default 4) is the number of blanks with which to
|
||||
begin each line.
|
||||
"""
|
||||
|
||||
blanks = ' ' * indent
|
||||
# Print the sorted list: 'x' may be a '--random' list or a set()
|
||||
print(textwrap.fill(' '.join(str(elt) for elt in sorted(x)), width,
|
||||
initial_indent=blanks, subsequent_indent=blanks),
|
||||
file=file)
|
||||
Loading…
Add table
Add a link
Reference in a new issue