|
8 | 8 | function's exact output, GitHub's escaping included. |
9 | 9 | * :class:`TestScriptsImportIt` loads each script that imports the helper in the |
10 | 10 | ways the steps and the tests do, and runs it as the steps do. |
| 11 | +* :class:`TestTheStepsCheckItOut` holds every sparse checkout of such a script |
| 12 | + to listing the helper too. |
11 | 13 |
|
12 | 14 | """ |
13 | 15 |
|
|
29 | 31 | from typing import TYPE_CHECKING |
30 | 32 | from unittest import mock |
31 | 33 |
|
| 34 | +from tests._workflows import WORKFLOWS, load |
32 | 35 | from util import _actions |
33 | 36 |
|
34 | 37 | if TYPE_CHECKING: |
35 | | - from typing import Iterator, Optional |
| 38 | + from typing import Any, Iterator, Optional |
36 | 39 |
|
37 | 40 | #: Test tier (#1958): reads and runs the tree's own scripts, a question about the tree. |
38 | 41 | __tier__ = 'LATEST' |
|
41 | 44 | HELPER = ROOT / 'util' / '_actions.py' |
42 | 45 | #: The scripts that import the helper. |
43 | 46 | SCRIPTS = ('apt_packages', 'check_suite_report', 'ci_timing', 'classify_changes', 'codeql_report', |
44 | | - 'coverage_report', 'leg_summary', 'pip_install', 'regenerate_samples', 'release_status', 'release_tags', |
45 | | - 'release_upload', 'release_vendor_update', 'update_python_versions', 'vendor_code_changed', |
46 | | - 'vendor_test_gate') |
| 47 | + 'coverage_report', 'discussion_report', 'leg_summary', 'pip_install', 'project_status', |
| 48 | + 'python_versions', 'regenerate_samples', 'release_status', 'release_tags', 'release_upload', |
| 49 | + 'release_vendor_update', 'superseded', 'update_python_versions', 'vendor_code_changed', |
| 50 | + 'vendor_test_gate', 'verdict_covers_checkout') |
47 | 51 | #: The top-level modules the helper may import, each in Python 3.7's standard |
48 | 52 | #: library: the running interpreter's :data:`sys.stdlib_module_names` would |
49 | 53 | #: pass ``tomllib``, which 3.7 lacks. |
|
56 | 60 | 'classify_changes': ([], {'OWN_PR': 'false'}), |
57 | 61 | 'codeql_report': (['--help'], {}), |
58 | 62 | 'coverage_report': (['--help'], {}), |
| 63 | + 'discussion_report': (['--help'], {}), |
59 | 64 | 'leg_summary': (['ktlo'], {'LEG': 'Python 3.8 (KTLO, non-blocking)', 'STEPS': '{}'}), |
60 | 65 | 'pip_install': (['--help'], {}), |
| 66 | + 'project_status': (['--help'], {}), |
| 67 | + 'python_versions': (['latest'], {}), |
61 | 68 | 'regenerate_samples': (['--help'], {}), |
62 | 69 | 'release_status': (['--help'], {}), |
63 | 70 | 'release_tags': (['--help'], {}), |
64 | 71 | 'release_upload': (['--help'], {}), |
65 | 72 | 'release_vendor_update': (['--help'], {}), |
| 73 | + 'superseded': (['--help'], {}), |
66 | 74 | 'update_python_versions': (['--help'], {}), |
67 | 75 | 'vendor_code_changed': (['--help'], {}), |
68 | 76 | 'vendor_test_gate': (['--help'], {}), |
| 77 | + 'verdict_covers_checkout': (['--help'], {}), |
69 | 78 | } |
70 | 79 | #: ``-X importtime``'s line for a module, by its name. |
71 | 80 | IMPORT_TIME = re.compile(r'^import time:.*\|\s*(\S+)\s*$', re.M) |
@@ -330,5 +339,42 @@ def test_run_as_the_steps_run_it(self) -> None: |
330 | 339 | self.assertEqual(output.read_text(encoding='utf-8'), 'code=true\n') |
331 | 340 |
|
332 | 341 |
|
| 342 | +def sparse_checkouts_missing_the_helper(spec: 'Any') -> 'list[tuple[str, list[str]]]': |
| 343 | + """Each job of the workflow ``spec`` whose sparse checkout lists a script of :data:`SCRIPTS` but not the helper.""" |
| 344 | + found = [] |
| 345 | + for job_id, job in (spec.get('jobs') or {}).items(): |
| 346 | + for step in job.get('steps') or []: |
| 347 | + listed = str((step.get('with') or {}).get('sparse-checkout') or '').split() |
| 348 | + scripts = [path for path in listed if path.startswith('util/') and path.endswith('.py') |
| 349 | + and path[len('util/'):-len('.py')] in SCRIPTS] |
| 350 | + if scripts and 'util/_actions.py' not in listed: |
| 351 | + found.append((job_id, scripts)) |
| 352 | + return found |
| 353 | + |
| 354 | + |
| 355 | +class TestTheStepsCheckItOut(unittest.TestCase): |
| 356 | + """A sparse checkout of a script that imports the helper holds the helper too, or the import fails.""" |
| 357 | + |
| 358 | + def test_every_sparse_checkout_of_a_script_lists_the_helper(self) -> None: |
| 359 | + checked = 0 |
| 360 | + for path in sorted(WORKFLOWS.glob('*.yml')): |
| 361 | + with self.subTest(workflow=path.name): |
| 362 | + spec = load(path.name) |
| 363 | + self.assertEqual(sparse_checkouts_missing_the_helper(spec), []) |
| 364 | + checked += sum('sparse-checkout' in (step.get('with') or {}) for job in spec['jobs'].values() |
| 365 | + for step in job.get('steps') or []) |
| 366 | + self.assertGreater(checked, 0, 'no sparse checkout was found to check') |
| 367 | + |
| 368 | + def test_the_check_sees_a_missing_helper(self) -> None: |
| 369 | + def spec(*listed: 'str') -> 'Any': |
| 370 | + return {'jobs': {'j': {'steps': [{'with': {'sparse-checkout': ''.join(f'{p}\n' for p in listed)}}]}}} |
| 371 | + |
| 372 | + self.assertEqual(sparse_checkouts_missing_the_helper(spec('.github/python-versions.toml', |
| 373 | + 'util/python_versions.py')), |
| 374 | + [('j', ['util/python_versions.py'])]) |
| 375 | + self.assertEqual(sparse_checkouts_missing_the_helper(spec('util/_actions.py', 'util/python_versions.py')), []) |
| 376 | + self.assertEqual(sparse_checkouts_missing_the_helper(spec('util/no_helper_here.py')), []) |
| 377 | + |
| 378 | + |
333 | 379 | if __name__ == '__main__': |
334 | 380 | unittest.main() |
0 commit comments