|
18 | 18 | from mypy.test.config import test_temp_dir |
19 | 19 | from mypy.test.data import DataDrivenTestCase, DataSuite |
20 | 20 | from mypy.test.helpers import assert_string_arrays_equal |
| 21 | +from mypy.test.update_data import update_testcase_output |
21 | 22 | from mypy.types import Type |
22 | 23 | from mypyc.analysis.ircheck import assert_func_ir_valid |
23 | 24 | from mypyc.common import IS_32_BIT_PLATFORM, PLATFORM_SIZE |
@@ -153,46 +154,20 @@ def build_ir_for_single_file2( |
153 | 154 | return module, tree, result.types, mapper |
154 | 155 |
|
155 | 156 |
|
156 | | -def update_testcase_output(testcase: DataDrivenTestCase, output: list[str]) -> None: |
157 | | - # TODO: backport this to mypy |
158 | | - assert testcase.old_cwd is not None, "test was not properly set up" |
159 | | - testcase_path = os.path.join(testcase.old_cwd, testcase.file) |
160 | | - with open(testcase_path) as f: |
161 | | - data_lines = f.read().splitlines() |
162 | | - |
163 | | - # We can't rely on the test line numbers to *find* the test, since |
164 | | - # we might fix multiple tests in a run. So find it by the case |
165 | | - # header. Give up if there are multiple tests with the same name. |
166 | | - test_slug = f"[case {testcase.name}]" |
167 | | - if data_lines.count(test_slug) != 1: |
168 | | - return |
169 | | - start_idx = data_lines.index(test_slug) |
170 | | - stop_idx = start_idx + 11 |
171 | | - while stop_idx < len(data_lines) and not data_lines[stop_idx].startswith("[case "): |
172 | | - stop_idx += 1 |
173 | | - |
174 | | - test = data_lines[start_idx:stop_idx] |
175 | | - out_start = test.index("[out]") |
176 | | - test[out_start + 1 :] = output |
177 | | - data_lines[start_idx:stop_idx] = test + [""] |
178 | | - data = "\n".join(data_lines) |
179 | | - |
180 | | - with open(testcase_path, "w") as f: |
181 | | - print(data, file=f) |
182 | | - |
183 | | - |
184 | 157 | def assert_test_output( |
185 | 158 | testcase: DataDrivenTestCase, |
186 | 159 | actual: list[str], |
187 | 160 | message: str, |
188 | 161 | expected: list[str] | None = None, |
189 | 162 | formatted: list[str] | None = None, |
| 163 | + *, |
| 164 | + incremental_step: int = 1, |
190 | 165 | ) -> None: |
191 | 166 | __tracebackhide__ = True |
192 | 167 |
|
193 | 168 | expected_output = expected if expected is not None else testcase.output |
194 | 169 | if expected_output != actual and testcase.config.getoption("--update-data", False): |
195 | | - update_testcase_output(testcase, actual) |
| 170 | + update_testcase_output(testcase, actual, incremental_step=incremental_step) |
196 | 171 |
|
197 | 172 | assert_string_arrays_equal( |
198 | 173 | expected_output, actual, f"{message} ({testcase.file}, line {testcase.line})" |
|
0 commit comments