upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts/run_semantic_tests.py
diff options
context:
space:
mode:
authorCody Smith <cody@protopt.com>2026-11-23 22:20:42 -0800
committerCody Smith <cody@protopt.com>2026-11-23 22:20:42 -0800
commit90eb7284feaae3d2e1511ffef0685d95a7dd7525 (patch)
treef64ca9694b0bc950edd92354e358a7685181872c /scripts/run_semantic_tests.py
parent973593f4a7c14cb70ba9827f2e5e04641294ff20 (diff)
Reject semantic-test timeouts beyond portable wait limits
Diffstat (limited to 'scripts/run_semantic_tests.py')
-rw-r--r--scripts/run_semantic_tests.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/scripts/run_semantic_tests.py b/scripts/run_semantic_tests.py
index 0a6f0d7f2..29382d5d2 100644
--- a/scripts/run_semantic_tests.py
+++ b/scripts/run_semantic_tests.py
@@ -17,7 +17,8 @@ or on a single core, it runs that discover command itself. Prints the output of
17line, and exits 1 if a file fails or none is found. Standard library only. 17line, and exits 1 if a file fails or none is found. Standard library only.
18 18
19`--timeout SECONDS` limits each module subprocess in parallel mode, or the entire discover subprocess with 19`--timeout SECONDS` limits each module subprocess in parallel mode, or the entire discover subprocess with
20`-j 1`. A timeout fails the run and reports any output already produced; other parallel modules keep running. 20`-j 1`. The value must be positive and at most 86400 seconds (24 hours), keeping it within platform wait limits.
21A timeout fails the run and reports any output already produced; other parallel modules keep running.
21The default has no time limit. This stops the direct test subprocess, not any descendants it may have started. 22The default has no time limit. This stops the direct test subprocess, not any descendants it may have started.
22""" 23"""
23import argparse 24import argparse
@@ -31,6 +32,8 @@ import subprocess
31import sys 32import sys
32import time 33import time
33 34
35MAX_TIMEOUT_SECONDS = 24 * 60 * 60
36
34 37
35def test_modules(directory, pattern="test*.py"): 38def test_modules(directory, pattern="test*.py"):
36 """Dotted names of the test modules unittest discover finds under `directory` (it enters packages only).""" 39 """Dotted names of the test modules unittest discover finds under `directory` (it enters packages only)."""
@@ -46,8 +49,9 @@ def test_modules(directory, pattern="test*.py"):
46 49
47def positive_seconds(value): 50def positive_seconds(value):
48 seconds = float(value) 51 seconds = float(value)
49 if not math.isfinite(seconds) or seconds <= 0: 52 if not math.isfinite(seconds) or not 0 < seconds <= MAX_TIMEOUT_SECONDS:
50 raise argparse.ArgumentTypeError("timeout must be a positive finite number of seconds") 53 raise argparse.ArgumentTypeError(
54 f"timeout must be a positive finite number of seconds no greater than {MAX_TIMEOUT_SECONDS} (24 hours)")
51 return seconds 55 return seconds
52 56
53 57
@@ -73,8 +77,8 @@ def main(argv=None):
73 ap.add_argument("-j", "--jobs", type=int, default=os.cpu_count() or 1, help="files at a time (default: cores)") 77 ap.add_argument("-j", "--jobs", type=int, default=os.cpu_count() or 1, help="files at a time (default: cores)")
74 ap.add_argument("-v", "--verbose", action="store_true", help="unittest -v, and print passing files' output") 78 ap.add_argument("-v", "--verbose", action="store_true", help="unittest -v, and print passing files' output")
75 ap.add_argument("--timeout", type=positive_seconds, default=None, metavar="SECONDS", 79 ap.add_argument("--timeout", type=positive_seconds, default=None, metavar="SECONDS",
76 help="positive finite time limit per module subprocess, or for the whole discover subprocess " 80 help=f"positive finite time limit up to {MAX_TIMEOUT_SECONDS} seconds (24 hours) per module "
77 "with -j 1 (default: no limit)") 81 "subprocess, or for the whole discover subprocess with -j 1 (default: no limit)")
78 a = ap.parse_args(argv) 82 a = ap.parse_args(argv)
79 directory = os.path.abspath(a.directory) 83 directory = os.path.abspath(a.directory)
80 modules = test_modules(directory, a.pattern) 84 modules = test_modules(directory, a.pattern)