Skip to content

Commit 68f2ade

Browse files
committed
gh-109276: regrtest: shorter list of resources
1 parent 1465386 commit 68f2ade

File tree

3 files changed

+64
-17
lines changed

3 files changed

+64
-17
lines changed

Lib/test/libregrtest/cmdline.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import shlex
44
import sys
55
from test.support import os_helper
6+
from .utils import ALL_RESOURCES, RESOURCE_NAMES
67

78

89
USAGE = """\
@@ -132,19 +133,6 @@
132133
"""
133134

134135

135-
ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network',
136-
'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'walltime')
137-
138-
# Other resources excluded from --use=all:
139-
#
140-
# - extralagefile (ex: test_zipfile64): really too slow to be enabled
141-
# "by default"
142-
# - tzdata: while needed to validate fully test_datetime, it makes
143-
# test_datetime too slow (15-20 min on some buildbots) and so is disabled by
144-
# default (see bpo-30822).
145-
RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata')
146-
147-
148136
class Namespace(argparse.Namespace):
149137
def __init__(self, **kwargs) -> None:
150138
self.ci = False

Lib/test/libregrtest/utils.py

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
EXIT_TIMEOUT = 120.0
3434

3535

36+
ALL_RESOURCES = ('audio', 'curses', 'largefile', 'network',
37+
'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', 'walltime')
38+
39+
# Other resources excluded from --use=all:
40+
#
41+
# - extralagefile (ex: test_zipfile64): really too slow to be enabled
42+
# "by default"
43+
# - tzdata: while needed to validate fully test_datetime, it makes
44+
# test_datetime too slow (15-20 min on some buildbots) and so is disabled by
45+
# default (see bpo-30822).
46+
RESOURCE_NAMES = ALL_RESOURCES + ('extralargefile', 'tzdata')
47+
48+
3649
# Types for types hints
3750
StrPath = str
3851
TestName = str
@@ -535,6 +548,31 @@ def is_cross_compiled():
535548
return ('_PYTHON_HOST_PLATFORM' in os.environ)
536549

537550

551+
def format_resources(use_resources: tuple[str, ...]):
552+
# set preserves insertion order
553+
use_resources = set(use_resources)
554+
all_resources = set(ALL_RESOURCES)
555+
556+
# Express resources relative to "all"
557+
relative_all = ['all']
558+
for name in all_resources - use_resources:
559+
relative_all.append(f'-{name}')
560+
for name in use_resources - all_resources:
561+
relative_all.append(f'+{name}')
562+
all_text = ', '.join(relative_all)
563+
all_text = f"resources: {all_text}"
564+
565+
# List of enabled resources
566+
text = ', '.join(sorted(use_resources))
567+
text = f"resources ({len(use_resources)}): {text}"
568+
569+
# Pick the shortest string (prefer relative to all if lengths are equal)
570+
if len(all_text) <= len(text):
571+
return all_text
572+
else:
573+
return text
574+
575+
538576
def display_header(use_resources: tuple[str, ...],
539577
python_cmd: tuple[str, ...] | None):
540578
# Print basic platform information
@@ -550,14 +588,15 @@ def display_header(use_resources: tuple[str, ...],
550588
if process_cpu_count and process_cpu_count != cpu_count:
551589
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
552590
print("== CPU count:", cpu_count)
553-
print("== encodings: locale=%s, FS=%s"
591+
print("== encodings: locale=%s FS=%s"
554592
% (locale.getencoding(), sys.getfilesystemencoding()))
555593

556594
if use_resources:
557-
print(f"== resources ({len(use_resources)}): "
558-
f"{', '.join(sorted(use_resources))}")
595+
text = format_resources(use_resources)
596+
print(f"== {text}")
559597
else:
560-
print("== resources: (all disabled, use -u option)")
598+
print("== resources: all test resources are disabled, "
599+
"use -u option to unskip tests")
561600

562601
cross_compile = is_cross_compiled()
563602
if cross_compile:

Lib/test/test_regrtest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,26 @@ def test_get_signal_name(self):
20802080
):
20812081
self.assertEqual(utils.get_signal_name(exitcode), expected, exitcode)
20822082

2083+
def test_format_resources(self):
2084+
format_resources = utils.format_resources
2085+
ALL_RESOURCES = utils.ALL_RESOURCES
2086+
self.assertEqual(
2087+
format_resources(("network",)),
2088+
'resources (1): network')
2089+
self.assertEqual(
2090+
format_resources(("audio", "decimal", "network")),
2091+
'resources (3): audio, decimal, network')
2092+
self.assertEqual(
2093+
format_resources(ALL_RESOURCES),
2094+
'resources: all')
2095+
self.assertEqual(
2096+
format_resources(tuple(name for name in ALL_RESOURCES
2097+
if name != "cpu")),
2098+
'resources: all, -cpu')
2099+
self.assertEqual(
2100+
format_resources((*ALL_RESOURCES, "tzdata")),
2101+
'resources: all, +tzdata')
2102+
20832103

20842104
if __name__ == '__main__':
20852105
unittest.main()

0 commit comments

Comments
 (0)