1
# Owner(s): ["module: ci"]
6
from torch.testing._internal.common_utils import TestCase, run_tests
13
class DeterminationTest(TestCase):
14
# Test determination on a subset of tests
20
"test_cpp_extensions_aot_ninja",
21
"test_cpp_extensions_aot_no_ninja",
28
def determined_tests(cls, changed_files):
29
changed_files = [os.path.normpath(path) for path in changed_files]
33
if run_test.should_run_test(run_test.TARGET_DET_LIST, test, changed_files, DummyOptions())
36
def test_target_det_list_is_sorted(self):
37
# We keep TARGET_DET_LIST sorted to minimize merge conflicts
38
# but most importantly to allow us to comment on the absence
39
# of a test. It would be very difficult to add a file right
40
# next to a comment that says to keep it out of the list.
41
self.assertListEqual(run_test.TARGET_DET_LIST, sorted(run_test.TARGET_DET_LIST))
43
def test_config_change_only(self):
44
"""CI configs trigger all tests"""
46
self.determined_tests([".ci/pytorch/test.sh"]), self.TESTS
49
def test_run_test(self):
50
"""run_test.py is imported by determination tests"""
52
self.determined_tests(["test/run_test.py"]), ["test_determination"]
55
def test_non_code_change(self):
56
"""Non-code changes don't trigger any tests"""
58
self.determined_tests(["CODEOWNERS", "README.md", "docs/doc.md"]), []
61
def test_cpp_file(self):
62
"""CPP files trigger all tests"""
64
self.determined_tests(["aten/src/ATen/native/cpu/Activation.cpp"]),
68
def test_test_file(self):
69
"""Test files trigger themselves and dependent tests"""
71
self.determined_tests(["test/test_jit.py"]), ["test_jit_profiling", "test_jit"]
74
self.determined_tests(["test/jit/test_custom_operators.py"]),
75
["test_jit_profiling", "test_jit"],
78
self.determined_tests(["test/quantization/eager/test_quantize_eager_ptq.py"]),
79
["test_quantization"],
82
def test_test_internal_file(self):
83
"""testing/_internal files trigger dependent tests"""
85
self.determined_tests(["torch/testing/_internal/common_quantization.py"]),
93
def test_torch_file(self):
94
"""Torch files trigger dependent tests"""
96
# Many files are force-imported to all tests,
97
# due to the layout of the project.
98
self.determined_tests(["torch/onnx/utils.py"]),
102
self.determined_tests(
104
"torch/autograd/_functions/utils.py",
105
"torch/autograd/_functions/utils.pyi",
111
self.determined_tests(["torch/utils/cpp_extension.py"]),
113
"test_cpp_extensions_aot_ninja",
114
"test_cpp_extensions_aot_no_ninja",
116
"test_determination",
120
def test_caffe2_file(self):
121
"""Caffe2 files trigger dependent tests"""
122
self.assertEqual(self.determined_tests(["caffe2/python/brew_test.py"]), [])
124
self.determined_tests(["caffe2/python/context.py"]), self.TESTS
127
def test_new_folder(self):
128
"""New top-level Python folder triggers all tests"""
129
self.assertEqual(self.determined_tests(["new_module/file.py"]), self.TESTS)
131
def test_new_test_script(self):
132
"""New test script triggers nothing (since it's not in run_tests.py)"""
133
self.assertEqual(self.determined_tests(["test/test_new_test_script.py"]), [])
136
if __name__ == "__main__":