diff options
author | Victor Stinner <vstinner@python.org> | 2023-10-04 09:39:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-04 09:39:50 (GMT) |
commit | efd8c7a7c97aa411098a4bee0ef1d428337deebb (patch) | |
tree | cb3fa74e80abaf886694e6bb7fde53b58173dc0a /Lib/test | |
parent | 1337765225d7d593169205672e004f97e15237ec (diff) | |
download | cpython-efd8c7a7c97aa411098a4bee0ef1d428337deebb.zip cpython-efd8c7a7c97aa411098a4bee0ef1d428337deebb.tar.gz cpython-efd8c7a7c97aa411098a4bee0ef1d428337deebb.tar.bz2 |
gh-109276: regrtest: shorter list of resources (#110326)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/libregrtest/cmdline.py | 14 | ||||
-rw-r--r-- | Lib/test/libregrtest/utils.py | 46 | ||||
-rw-r--r-- | Lib/test/test_regrtest.py | 20 |
3 files changed, 63 insertions, 17 deletions
diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index 7cfe904..dd4cd33 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -3,6 +3,7 @@ import os.path import shlex import sys from test.support import os_helper +from .utils import ALL_RESOURCES, RESOURCE_NAMES USAGE = """\ @@ -132,19 +133,6 @@ Pattern examples: """ -ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network', - 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'walltime') - -# Other resources excluded from --use=all: -# -# - extralagefile (ex: test_zipfile64): really too slow to be enabled -# "by default" -# - tzdata: while needed to validate fully test_datetime, it makes -# test_datetime too slow (15-20 min on some buildbots) and so is disabled by -# default (see bpo-30822). -RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata') - - class Namespace(argparse.Namespace): def __init__(self, **kwargs) -> None: self.ci = False diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 86fb820..ea2086c 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -33,6 +33,19 @@ WORKER_WORK_DIR_PREFIX = WORK_DIR_PREFIX + 'worker_' EXIT_TIMEOUT = 120.0 +ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network', + 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'walltime') + +# Other resources excluded from --use=all: +# +# - extralagefile (ex: test_zipfile64): really too slow to be enabled +# "by default" +# - tzdata: while needed to validate fully test_datetime, it makes +# test_datetime too slow (15-20 min on some buildbots) and so is disabled by +# default (see bpo-30822). +RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata') + + # Types for types hints StrPath = str TestName = str @@ -535,6 +548,30 @@ def is_cross_compiled(): return ('_PYTHON_HOST_PLATFORM' in os.environ) +def format_resources(use_resources: tuple[str, ...]): + use_resources = set(use_resources) + all_resources = set(ALL_RESOURCES) + + # Express resources relative to "all" + relative_all = ['all'] + for name in sorted(all_resources - use_resources): + relative_all.append(f'-{name}') + for name in sorted(use_resources - all_resources): + relative_all.append(f'{name}') + all_text = ','.join(relative_all) + all_text = f"resources: {all_text}" + + # List of enabled resources + text = ','.join(sorted(use_resources)) + text = f"resources ({len(use_resources)}): {text}" + + # Pick the shortest string (prefer relative to all if lengths are equal) + if len(all_text) <= len(text): + return all_text + else: + return text + + def display_header(use_resources: tuple[str, ...], python_cmd: tuple[str, ...] | None): # Print basic platform information @@ -550,14 +587,15 @@ def display_header(use_resources: tuple[str, ...], if process_cpu_count and process_cpu_count != cpu_count: cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)" print("== CPU count:", cpu_count) - print("== encodings: locale=%s, FS=%s" + print("== encodings: locale=%s FS=%s" % (locale.getencoding(), sys.getfilesystemencoding())) if use_resources: - print(f"== resources ({len(use_resources)}): " - f"{', '.join(sorted(use_resources))}") + text = format_resources(use_resources) + print(f"== {text}") else: - print("== resources: (all disabled, use -u option)") + print("== resources: all test resources are disabled, " + "use -u option to unskip tests") cross_compile = is_cross_compiled() if cross_compile: diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index ba23b36..f24d23e 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -2080,6 +2080,26 @@ class TestUtils(unittest.TestCase): ): self.assertEqual(utils.get_signal_name(exitcode), expected, exitcode) + def test_format_resources(self): + format_resources = utils.format_resources + ALL_RESOURCES = utils.ALL_RESOURCES + self.assertEqual( + format_resources(("network",)), + 'resources (1): network') + self.assertEqual( + format_resources(("audio", "decimal", "network")), + 'resources (3): audio,decimal,network') + self.assertEqual( + format_resources(ALL_RESOURCES), + 'resources: all') + self.assertEqual( + format_resources(tuple(name for name in ALL_RESOURCES + if name != "cpu")), + 'resources: all,-cpu') + self.assertEqual( + format_resources((*ALL_RESOURCES, "tzdata")), + 'resources: all,tzdata') + if __name__ == '__main__': unittest.main() |