Skip to content

Commit 773cd81

Browse files
[3.13] compute-changes.py: Fix & test process_changed_files() (GH-144674) (#145014)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
1 parent 11c61b5 commit 773cd81

File tree

3 files changed

+146
-2
lines changed

3 files changed

+146
-2
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
# GitHub
88
.github/** @ezio-melotti @hugovk @webknjaz
9+
Tools/build/compute-changes.py @AA-Turner @hugovk @webknjaz
10+
Lib/test/test_tools/test_compute_changes.py @AA-Turner @hugovk @webknjaz
911

1012
# pre-commit
1113
.pre-commit-config.yaml @hugovk
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
"""Tests to cover the Tools/build/compute-changes.py script."""
2+
3+
import importlib
4+
import os
5+
import unittest
6+
from pathlib import Path
7+
from unittest.mock import patch
8+
9+
from test.test_tools import skip_if_missing, imports_under_tool
10+
11+
skip_if_missing("build")
12+
13+
with patch.dict(os.environ, {"GITHUB_DEFAULT_BRANCH": "main"}):
14+
with imports_under_tool("build"):
15+
compute_changes = importlib.import_module("compute-changes")
16+
17+
process_changed_files = compute_changes.process_changed_files
18+
Outputs = compute_changes.Outputs
19+
ANDROID_DIRS = compute_changes.ANDROID_DIRS
20+
MACOS_DIRS = compute_changes.MACOS_DIRS
21+
WASI_DIRS = compute_changes.WASI_DIRS
22+
RUN_TESTS_IGNORE = compute_changes.RUN_TESTS_IGNORE
23+
UNIX_BUILD_SYSTEM_FILE_NAMES = compute_changes.UNIX_BUILD_SYSTEM_FILE_NAMES
24+
LIBRARY_FUZZER_PATHS = compute_changes.LIBRARY_FUZZER_PATHS
25+
26+
27+
class TestProcessChangedFiles(unittest.TestCase):
28+
29+
def test_windows(self):
30+
f = {Path(".github/workflows/reusable-windows.yml")}
31+
result = process_changed_files(f)
32+
self.assertTrue(result.run_tests)
33+
self.assertTrue(result.run_windows_tests)
34+
35+
def test_docs(self):
36+
for f in (
37+
".github/workflows/reusable-docs.yml",
38+
"Doc/library/datetime.rst",
39+
"Doc/Makefile",
40+
):
41+
with self.subTest(f=f):
42+
result = process_changed_files({Path(f)})
43+
self.assertTrue(result.run_docs)
44+
self.assertFalse(result.run_tests)
45+
46+
def test_ci_fuzz_stdlib(self):
47+
for p in LIBRARY_FUZZER_PATHS:
48+
with self.subTest(p=p):
49+
if p.is_dir():
50+
f = p / "file"
51+
elif p.is_file():
52+
f = p
53+
else:
54+
continue
55+
result = process_changed_files({f})
56+
self.assertTrue(result.run_ci_fuzz_stdlib)
57+
58+
def test_android(self):
59+
for d in ANDROID_DIRS:
60+
with self.subTest(d=d):
61+
result = process_changed_files({Path(d) / "file"})
62+
self.assertTrue(result.run_tests)
63+
self.assertTrue(result.run_android)
64+
self.assertFalse(result.run_windows_tests)
65+
66+
def test_macos(self):
67+
f = {Path(".github/workflows/reusable-macos.yml")}
68+
result = process_changed_files(f)
69+
self.assertTrue(result.run_tests)
70+
self.assertTrue(result.run_macos)
71+
72+
for d in MACOS_DIRS:
73+
with self.subTest(d=d):
74+
result = process_changed_files({Path(d) / "file"})
75+
self.assertTrue(result.run_tests)
76+
self.assertTrue(result.run_macos)
77+
self.assertFalse(result.run_windows_tests)
78+
79+
def test_wasi(self):
80+
f = {Path(".github/workflows/reusable-wasi.yml")}
81+
result = process_changed_files(f)
82+
self.assertTrue(result.run_tests)
83+
self.assertTrue(result.run_wasi)
84+
85+
for d in WASI_DIRS:
86+
with self.subTest(d=d):
87+
result = process_changed_files({d / "file"})
88+
self.assertTrue(result.run_tests)
89+
self.assertTrue(result.run_wasi)
90+
self.assertFalse(result.run_windows_tests)
91+
92+
def test_unix(self):
93+
for f in UNIX_BUILD_SYSTEM_FILE_NAMES:
94+
with self.subTest(f=f):
95+
result = process_changed_files({f})
96+
self.assertTrue(result.run_tests)
97+
self.assertFalse(result.run_windows_tests)
98+
99+
def test_msi(self):
100+
for f in (
101+
".github/workflows/reusable-windows-msi.yml",
102+
"Tools/msi/build.bat",
103+
):
104+
with self.subTest(f=f):
105+
result = process_changed_files({Path(f)})
106+
self.assertTrue(result.run_windows_msi)
107+
108+
def test_all_run(self):
109+
for f in (
110+
".github/workflows/some-new-workflow.yml",
111+
".github/workflows/build.yml",
112+
):
113+
with self.subTest(f=f):
114+
result = process_changed_files({Path(f)})
115+
self.assertTrue(result.run_tests)
116+
self.assertTrue(result.run_android)
117+
self.assertTrue(result.run_macos)
118+
self.assertTrue(result.run_ubuntu)
119+
self.assertTrue(result.run_wasi)
120+
121+
def test_all_ignored(self):
122+
for f in RUN_TESTS_IGNORE:
123+
with self.subTest(f=f):
124+
self.assertEqual(process_changed_files({Path(f)}), Outputs())
125+
126+
def test_wasi_and_android(self):
127+
f = {Path(".github/workflows/reusable-wasi.yml"), Path("Android/file")}
128+
result = process_changed_files(f)
129+
self.assertTrue(result.run_tests)
130+
self.assertTrue(result.run_wasi)
131+
132+
133+
if __name__ == "__main__":
134+
unittest.main()

Tools/build/compute-changes.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,27 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
220220

221221
if file.parent == GITHUB_WORKFLOWS_PATH:
222222
if file.name in ("build.yml", "reusable-cifuzz.yml"):
223-
run_tests = run_ci_fuzz = run_ci_fuzz_stdlib = True
223+
run_tests = run_ci_fuzz = run_ci_fuzz_stdlib = run_windows_tests = True
224224
has_platform_specific_change = False
225+
continue
225226
if file.name == "reusable-docs.yml":
226227
run_docs = True
228+
continue
229+
if file.name == "reusable-windows.yml":
230+
run_tests = True
231+
run_windows_tests = True
232+
continue
227233
if file.name == "reusable-windows-msi.yml":
228234
run_windows_msi = True
235+
continue
229236
if file.name == "reusable-macos.yml":
230237
run_tests = True
231238
platforms_changed.add("macos")
239+
continue
232240
if file.name == "reusable-wasi.yml":
233241
run_tests = True
234242
platforms_changed.add("wasi")
235-
continue
243+
continue
236244

237245
if not doc_file and file not in RUN_TESTS_IGNORE:
238246
run_tests = True

0 commit comments

Comments
 (0)