Skip to content

Commit 73ad79e

Browse files
committed
gh-109276: regrtest: shorter list of resources
1 parent bfe7e72 commit 73ad79e

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-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 = """\
@@ -130,19 +131,6 @@
130131
"""
131132

132133

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

Lib/test/libregrtest/utils.py

Lines changed: 37 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,25 @@ def is_cross_compiled():
535548
return ('_PYTHON_HOST_PLATFORM' in os.environ)
536549

537550

551+
def format_resources(use_resources: tuple[str, ...]):
552+
# Express resources related to "all"
553+
all_minus = [name for name in ALL_RESOURCES
554+
if name not in use_resources]
555+
all_minus.insert(0, 'all')
556+
all_minus = ',-'.join(all_minus)
557+
all_add = [name for name in use_resources
558+
if name not in ALL_RESOURCES]
559+
all_add.insert(0, all_minus)
560+
all_add = ','.join(all_add)
561+
all_text = f"resources: {all_add}"
562+
563+
text = ', '.join(sorted(use_resources))
564+
text = f"resources ({len(use_resources)}): {text}"
565+
if len(all_text) <= len(text):
566+
text = all_text
567+
return text
568+
569+
538570
def display_header(use_resources: tuple[str, ...],
539571
python_cmd: tuple[str, ...] | None):
540572
# Print basic platform information
@@ -550,14 +582,15 @@ def display_header(use_resources: tuple[str, ...],
550582
if process_cpu_count and process_cpu_count != cpu_count:
551583
cpu_count = f"{process_cpu_count} (process) / {cpu_count} (system)"
552584
print("== CPU count:", cpu_count)
553-
print("== encodings: locale=%s, FS=%s"
585+
print("== encodings: locale=%s FS=%s"
554586
% (locale.getencoding(), sys.getfilesystemencoding()))
555587

556588
if use_resources:
557-
print(f"== resources ({len(use_resources)}): "
558-
f"{', '.join(sorted(use_resources))}")
589+
text = format_resources(use_resources)
590+
print(f"== {text}")
559591
else:
560-
print("== resources: (all disabled, use -u option)")
592+
print("== resources: all test resources are disabled, "
593+
"use -u option to unskip tests")
561594

562595
cross_compile = is_cross_compiled()
563596
if cross_compile:

Lib/test/test_regrtest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,23 @@ def test_get_signal_name(self):
20762076
):
20772077
self.assertEqual(utils.get_signal_name(exitcode), expected, exitcode)
20782078

2079+
def test_format_resources(self):
2080+
format_resources = utils.format_resources
2081+
ALL_RESOURCES = utils.ALL_RESOURCES
2082+
self.assertEqual(
2083+
format_resources(("network",)),
2084+
'resources (1): network')
2085+
self.assertEqual(
2086+
format_resources(ALL_RESOURCES),
2087+
'resources: all')
2088+
self.assertEqual(
2089+
format_resources(tuple(name for name in ALL_RESOURCES
2090+
if name != "cpu")),
2091+
'resources: all,-cpu')
2092+
self.assertEqual(
2093+
format_resources((*ALL_RESOURCES, "tzdata")),
2094+
'resources: all,tzdata')
2095+
20792096

20802097
if __name__ == '__main__':
20812098
unittest.main()

0 commit comments

Comments
 (0)