1
# Owner(s): ["module: ci"]
7
from torch.testing._internal.common_utils import run_tests, TestCase
14
class DeterminationTest(TestCase):
15
# Test determination on a subset of tests
21
"test_cpp_extensions_aot_ninja",
22
"test_cpp_extensions_aot_no_ninja",
29
def determined_tests(cls, changed_files):
30
changed_files = [os.path.normpath(path) for path in changed_files]
34
if run_test.should_run_test(
35
run_test.TARGET_DET_LIST, test, changed_files, DummyOptions()
39
def test_target_det_list_is_sorted(self):
40
# We keep TARGET_DET_LIST sorted to minimize merge conflicts
41
# but most importantly to allow us to comment on the absence
42
# of a test. It would be very difficult to add a file right
43
# next to a comment that says to keep it out of the list.
44
self.assertListEqual(run_test.TARGET_DET_LIST, sorted(run_test.TARGET_DET_LIST))
46
def test_config_change_only(self):
47
"""CI configs trigger all tests"""
48
self.assertEqual(self.determined_tests([".ci/pytorch/test.sh"]), self.TESTS)
50
def test_run_test(self):
51
"""run_test.py is imported by determination tests"""
53
self.determined_tests(["test/run_test.py"]), ["test_determination"]
56
def test_non_code_change(self):
57
"""Non-code changes don't trigger any tests"""
59
self.determined_tests(["CODEOWNERS", "README.md", "docs/doc.md"]), []
62
def test_cpp_file(self):
63
"""CPP files trigger all tests"""
65
self.determined_tests(["aten/src/ATen/native/cpu/Activation.cpp"]),
69
def test_test_file(self):
70
"""Test files trigger themselves and dependent tests"""
72
self.determined_tests(["test/test_jit.py"]),
73
["test_jit_profiling", "test_jit"],
76
self.determined_tests(["test/jit/test_custom_operators.py"]),
77
["test_jit_profiling", "test_jit"],
80
self.determined_tests(
81
["test/quantization/eager/test_quantize_eager_ptq.py"]
83
["test_quantization"],
86
def test_test_internal_file(self):
87
"""testing/_internal files trigger dependent tests"""
89
self.determined_tests(["torch/testing/_internal/common_quantization.py"]),
97
def test_torch_file(self):
98
"""Torch files trigger dependent tests"""
100
# Many files are force-imported to all tests,
101
# due to the layout of the project.
102
self.determined_tests(["torch/onnx/utils.py"]),
106
self.determined_tests(
108
"torch/autograd/_functions/utils.py",
109
"torch/autograd/_functions/utils.pyi",
115
self.determined_tests(["torch/utils/cpp_extension.py"]),
117
"test_cpp_extensions_aot_ninja",
118
"test_cpp_extensions_aot_no_ninja",
120
"test_determination",
124
def test_new_folder(self):
125
"""New top-level Python folder triggers all tests"""
126
self.assertEqual(self.determined_tests(["new_module/file.py"]), self.TESTS)
128
def test_new_test_script(self):
129
"""New test script triggers nothing (since it's not in run_tests.py)"""
130
self.assertEqual(self.determined_tests(["test/test_new_test_script.py"]), [])
133
if __name__ == "__main__":