| 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 |
IOS_DIRS = compute_changes.IOS_DIRS |
| 21 |
MACOS_DIRS = compute_changes.MACOS_DIRS |
| 22 |
WASI_DIRS = compute_changes.WASI_DIRS |
| 23 |
RUN_TESTS_IGNORE = compute_changes.RUN_TESTS_IGNORE |
| 24 |
UNIX_BUILD_SYSTEM_FILE_NAMES = compute_changes.UNIX_BUILD_SYSTEM_FILE_NAMES |
| 25 |
LIBRARY_FUZZER_PATHS = compute_changes.LIBRARY_FUZZER_PATHS |
| 26 |
|
| 27 |
|
| 28 |
class TestProcessChangedFiles(unittest.TestCase): |
| 29 |
|
| 30 |
def test_windows(self): |
| 31 |
f = {Path(".github/workflows/reusable-windows.yml")} |
| 32 |
result = process_changed_files(f) |
| 33 |
self.assertTrue(result.run_tests) |
| 34 |
self.assertTrue(result.run_windows_tests) |
| 35 |
|
| 36 |
def test_docs(self): |
| 37 |
for f in ( |
| 38 |
".github/workflows/reusable-docs.yml", |
| 39 |
"Doc/library/datetime.rst", |
| 40 |
"Doc/Makefile", |
| 41 |
): |
| 42 |
with self.subTest(f=f): |
| 43 |
result = process_changed_files({Path(f)}) |
| 44 |
self.assertTrue(result.run_docs) |
| 45 |
self.assertFalse(result.run_tests) |
| 46 |
|
| 47 |
def test_ci_fuzz_stdlib(self): |
| 48 |
for p in LIBRARY_FUZZER_PATHS: |
| 49 |
with self.subTest(p=p): |
| 50 |
if p.is_dir(): |
| 51 |
f = p / "file" |
| 52 |
elif p.is_file(): |
| 53 |
f = p |
| 54 |
else: |
| 55 |
continue |
| 56 |
result = process_changed_files({f}) |
| 57 |
self.assertTrue(result.run_ci_fuzz_stdlib) |
| 58 |
|
| 59 |
def test_android(self): |
| 60 |
for d in ANDROID_DIRS: |
| 61 |
with self.subTest(d=d): |
| 62 |
result = process_changed_files({Path(d) / "file"}) |
| 63 |
self.assertTrue(result.run_tests) |
| 64 |
self.assertTrue(result.run_android) |
| 65 |
self.assertFalse(result.run_windows_tests) |
| 66 |
|
| 67 |
def test_ios(self): |
| 68 |
for d in IOS_DIRS: |
| 69 |
with self.subTest(d=d): |
| 70 |
result = process_changed_files({Path(d) / "file"}) |
| 71 |
self.assertTrue(result.run_tests) |
| 72 |
self.assertTrue(result.run_ios) |
| 73 |
self.assertFalse(result.run_windows_tests) |
| 74 |
|
| 75 |
def test_macos(self): |
| 76 |
f = {Path(".github/workflows/reusable-macos.yml")} |
| 77 |
result = process_changed_files(f) |
| 78 |
self.assertTrue(result.run_tests) |
| 79 |
self.assertTrue(result.run_macos) |
| 80 |
|
| 81 |
for d in MACOS_DIRS: |
| 82 |
with self.subTest(d=d): |
| 83 |
result = process_changed_files({Path(d) / "file"}) |
| 84 |
self.assertTrue(result.run_tests) |
| 85 |
self.assertTrue(result.run_macos) |
| 86 |
self.assertFalse(result.run_windows_tests) |
| 87 |
|
| 88 |
def test_wasi(self): |
| 89 |
f = {Path(".github/workflows/reusable-wasi.yml")} |
| 90 |
result = process_changed_files(f) |
| 91 |
self.assertTrue(result.run_tests) |
| 92 |
self.assertTrue(result.run_wasi) |
| 93 |
|
| 94 |
for d in WASI_DIRS: |
| 95 |
with self.subTest(d=d): |
| 96 |
result = process_changed_files({d / "file"}) |
| 97 |
self.assertTrue(result.run_tests) |
| 98 |
self.assertTrue(result.run_wasi) |
| 99 |
self.assertFalse(result.run_windows_tests) |
| 100 |
|
| 101 |
def test_unix(self): |
| 102 |
for f in UNIX_BUILD_SYSTEM_FILE_NAMES: |
| 103 |
with self.subTest(f=f): |
| 104 |
result = process_changed_files({f}) |
| 105 |
self.assertTrue(result.run_tests) |
| 106 |
self.assertFalse(result.run_windows_tests) |
| 107 |
|
| 108 |
def test_msi(self): |
| 109 |
for f in ( |
| 110 |
".github/workflows/reusable-windows-msi.yml", |
| 111 |
"Tools/msi/build.bat", |
| 112 |
): |
| 113 |
with self.subTest(f=f): |
| 114 |
result = process_changed_files({Path(f)}) |
| 115 |
self.assertTrue(result.run_windows_msi) |
| 116 |
|
| 117 |
def test_all_run(self): |
| 118 |
for f in ( |
| 119 |
".github/workflows/some-new-workflow.yml", |
| 120 |
".github/workflows/build.yml", |
| 121 |
): |
| 122 |
with self.subTest(f=f): |
| 123 |
result = process_changed_files({Path(f)}) |
| 124 |
self.assertTrue(result.run_tests) |
| 125 |
self.assertTrue(result.run_android) |
| 126 |
self.assertTrue(result.run_ios) |
| 127 |
self.assertTrue(result.run_macos) |
| 128 |
self.assertTrue(result.run_ubuntu) |
| 129 |
self.assertTrue(result.run_wasi) |
| 130 |
|
| 131 |
def test_all_ignored(self): |
| 132 |
for f in RUN_TESTS_IGNORE: |
| 133 |
with self.subTest(f=f): |
| 134 |
self.assertEqual(process_changed_files({Path(f)}), Outputs()) |
| 135 |
|
| 136 |
def test_wasi_and_android(self): |
| 137 |
f = {Path(".github/workflows/reusable-wasi.yml"), Path("Android/file")} |
| 138 |
result = process_changed_files(f) |
| 139 |
self.assertTrue(result.run_tests) |
| 140 |
self.assertTrue(result.run_wasi) |
| 141 |
|
| 142 |
|
| 143 |
if __name__ == "__main__": |
| 144 |
unittest.main() |