|
9 | 9 | from typing import Tuple, List, Dict, Set |
10 | 10 |
|
11 | 11 | from mypy import build, defaults |
12 | | -import mypy.myunit # for mutable globals (ick!) |
13 | 12 | from mypy.build import BuildSource, find_module_clear_caches |
14 | | -from mypy.myunit import Suite, AssertionFailure |
| 13 | +from mypy.myunit import AssertionFailure |
15 | 14 | from mypy.test.config import test_temp_dir, test_data_prefix |
16 | | -from mypy.test.data import parse_test_cases, DataDrivenTestCase |
| 15 | +from mypy.test.data import parse_test_cases, DataDrivenTestCase, DataSuite |
17 | 16 | from mypy.test.helpers import ( |
18 | 17 | assert_string_arrays_equal, normalize_error_messages, |
19 | 18 | testcase_pyversion, update_testcase_output, |
|
67 | 66 | ] |
68 | 67 |
|
69 | 68 |
|
70 | | -class TypeCheckSuite(Suite): |
| 69 | +class TypeCheckSuite(DataSuite): |
| 70 | + def __init__(self, *, update_data=False): |
| 71 | + self.update_data = update_data |
71 | 72 |
|
72 | | - def cases(self) -> List[DataDrivenTestCase]: |
| 73 | + @classmethod |
| 74 | + def cases(cls) -> List[DataDrivenTestCase]: |
73 | 75 | c = [] # type: List[DataDrivenTestCase] |
74 | 76 | for f in files: |
75 | 77 | c += parse_test_cases(os.path.join(test_data_prefix, f), |
76 | | - self.run_test, test_temp_dir, True) |
| 78 | + None, test_temp_dir, True) |
77 | 79 | return c |
78 | 80 |
|
79 | | - def run_test(self, testcase: DataDrivenTestCase) -> None: |
| 81 | + def run_case(self, testcase: DataDrivenTestCase) -> None: |
80 | 82 | incremental = 'incremental' in testcase.name.lower() or 'incremental' in testcase.file |
81 | 83 | optional = 'optional' in testcase.file |
82 | 84 | if incremental: |
83 | 85 | # Incremental tests are run once with a cold cache, once with a warm cache. |
84 | 86 | # Expect success on first run, errors from testcase.output (if any) on second run. |
85 | 87 | # We briefly sleep to make sure file timestamps are distinct. |
86 | 88 | self.clear_cache() |
87 | | - self.run_test_once(testcase, 1) |
| 89 | + self.run_case_once(testcase, 1) |
88 | 90 | time.sleep(0.1) |
89 | | - self.run_test_once(testcase, 2) |
| 91 | + self.run_case_once(testcase, 2) |
90 | 92 | elif optional: |
91 | 93 | try: |
92 | 94 | experiments.STRICT_OPTIONAL = True |
93 | | - self.run_test_once(testcase) |
| 95 | + self.run_case_once(testcase) |
94 | 96 | finally: |
95 | 97 | experiments.STRICT_OPTIONAL = False |
96 | 98 | else: |
97 | | - self.run_test_once(testcase) |
| 99 | + self.run_case_once(testcase) |
98 | 100 |
|
99 | 101 | def clear_cache(self) -> None: |
100 | 102 | dn = defaults.MYPY_CACHE |
101 | 103 |
|
102 | 104 | if os.path.exists(dn): |
103 | 105 | shutil.rmtree(dn) |
104 | 106 |
|
105 | | - def run_test_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: |
| 107 | + def run_case_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: |
106 | 108 | find_module_clear_caches() |
107 | 109 | program_text = '\n'.join(testcase.input) |
108 | 110 | module_name, program_name, program_text = self.parse_module(program_text) |
@@ -140,8 +142,8 @@ def run_test_once(self, testcase: DataDrivenTestCase, incremental=0) -> None: |
140 | 142 | a = e.messages |
141 | 143 | a = normalize_error_messages(a) |
142 | 144 |
|
143 | | - if output != a and mypy.myunit.UPDATE_TESTCASES: |
144 | | - update_testcase_output(testcase, a, mypy.myunit.APPEND_TESTCASES) |
| 145 | + if output != a and self.update_data: |
| 146 | + update_testcase_output(testcase, a) |
145 | 147 |
|
146 | 148 | assert_string_arrays_equal( |
147 | 149 | output, a, |
|
0 commit comments