pytorch

Форк
0
/
test_determination.py 
137 строк · 4.4 Кб
1
# Owner(s): ["module: ci"]
2

3
import os
4

5
import run_test
6
from torch.testing._internal.common_utils import TestCase, run_tests
7

8

9
class DummyOptions:
10
    verbose = False
11

12

13
class DeterminationTest(TestCase):
14
    # Test determination on a subset of tests
15
    TESTS = [
16
        "test_nn",
17
        "test_jit_profiling",
18
        "test_jit",
19
        "test_torch",
20
        "test_cpp_extensions_aot_ninja",
21
        "test_cpp_extensions_aot_no_ninja",
22
        "test_utils",
23
        "test_determination",
24
        "test_quantization",
25
    ]
26

27
    @classmethod
28
    def determined_tests(cls, changed_files):
29
        changed_files = [os.path.normpath(path) for path in changed_files]
30
        return [
31
            test
32
            for test in cls.TESTS
33
            if run_test.should_run_test(run_test.TARGET_DET_LIST, test, changed_files, DummyOptions())
34
        ]
35

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))
42

43
    def test_config_change_only(self):
44
        """CI configs trigger all tests"""
45
        self.assertEqual(
46
            self.determined_tests([".ci/pytorch/test.sh"]), self.TESTS
47
        )
48

49
    def test_run_test(self):
50
        """run_test.py is imported by determination tests"""
51
        self.assertEqual(
52
            self.determined_tests(["test/run_test.py"]), ["test_determination"]
53
        )
54

55
    def test_non_code_change(self):
56
        """Non-code changes don't trigger any tests"""
57
        self.assertEqual(
58
            self.determined_tests(["CODEOWNERS", "README.md", "docs/doc.md"]), []
59
        )
60

61
    def test_cpp_file(self):
62
        """CPP files trigger all tests"""
63
        self.assertEqual(
64
            self.determined_tests(["aten/src/ATen/native/cpu/Activation.cpp"]),
65
            self.TESTS,
66
        )
67

68
    def test_test_file(self):
69
        """Test files trigger themselves and dependent tests"""
70
        self.assertEqual(
71
            self.determined_tests(["test/test_jit.py"]), ["test_jit_profiling", "test_jit"]
72
        )
73
        self.assertEqual(
74
            self.determined_tests(["test/jit/test_custom_operators.py"]),
75
            ["test_jit_profiling", "test_jit"],
76
        )
77
        self.assertEqual(
78
            self.determined_tests(["test/quantization/eager/test_quantize_eager_ptq.py"]),
79
            ["test_quantization"],
80
        )
81

82
    def test_test_internal_file(self):
83
        """testing/_internal files trigger dependent tests"""
84
        self.assertEqual(
85
            self.determined_tests(["torch/testing/_internal/common_quantization.py"]),
86
            [
87
                "test_jit_profiling",
88
                "test_jit",
89
                "test_quantization",
90
            ],
91
        )
92

93
    def test_torch_file(self):
94
        """Torch files trigger dependent tests"""
95
        self.assertEqual(
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"]),
99
            self.TESTS,
100
        )
101
        self.assertEqual(
102
            self.determined_tests(
103
                [
104
                    "torch/autograd/_functions/utils.py",
105
                    "torch/autograd/_functions/utils.pyi",
106
                ]
107
            ),
108
            ["test_utils"],
109
        )
110
        self.assertEqual(
111
            self.determined_tests(["torch/utils/cpp_extension.py"]),
112
            [
113
                "test_cpp_extensions_aot_ninja",
114
                "test_cpp_extensions_aot_no_ninja",
115
                "test_utils",
116
                "test_determination",
117
            ],
118
        )
119

120
    def test_caffe2_file(self):
121
        """Caffe2 files trigger dependent tests"""
122
        self.assertEqual(self.determined_tests(["caffe2/python/brew_test.py"]), [])
123
        self.assertEqual(
124
            self.determined_tests(["caffe2/python/context.py"]), self.TESTS
125
        )
126

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)
130

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"]), [])
134

135

136
if __name__ == "__main__":
137
    run_tests()
138

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.