Debian Codegraph @

Lib/test/test_tools/test_compute_changes.py

raw
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()