Skip to content

gh-109276: regrtest: shorter list of resources #110326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions Lib/test/libregrtest/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import shlex
import sys
from test.support import os_helper
from .utils import ALL_RESOURCES, RESOURCE_NAMES


USAGE = """\
Expand Down Expand Up @@ -132,19 +133,6 @@
"""


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
Expand Down
46 changes: 42 additions & 4 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
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
Expand Down Expand Up @@ -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}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
relative_all.append(f'{name}')
relative_all.append(name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. Sadly, I saw your comment after the change was merged. I make try to include it in my next regrtest change ;-)

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
Expand All @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,26 @@ def test_get_signal_name(self):
):
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()