]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109276: regrtest: shorter list of resources (#110326)
authorVictor Stinner <vstinner@python.org>
Wed, 4 Oct 2023 09:39:50 +0000 (11:39 +0200)
committerGitHub <noreply@github.com>
Wed, 4 Oct 2023 09:39:50 +0000 (09:39 +0000)
Lib/test/libregrtest/cmdline.py
Lib/test/libregrtest/utils.py
Lib/test/test_regrtest.py

index 7cfe904cb5a53528fbddcde843697ecf9600d78d..dd4cd335bef7e3e31ca6c8f44efd0ffa71283e4c 100644 (file)
@@ -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
index 86fb820a23f535c24d6433a8f48265c37fb58981..ea2086cd71b173db76b6553ea5a3fe89fb731456 100644 (file)
@@ -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:
index ba23b3666924c47f28cec6e2f1be34198b73c014..f24d23e5c2f7314ce91b9fbf1b0b6ab814b810df 100644 (file)
@@ -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()