(testcase: DataDrivenTestCase, output: list[str])
| 144 | |
| 145 | |
| 146 | def update_testcase_output(testcase: DataDrivenTestCase, output: list[str]) -> None: |
| 147 | # TODO: backport this to mypy |
| 148 | assert testcase.old_cwd is not None, "test was not properly set up" |
| 149 | testcase_path = os.path.join(testcase.old_cwd, testcase.file) |
| 150 | with open(testcase_path) as f: |
| 151 | data_lines = f.read().splitlines() |
| 152 | |
| 153 | # We can't rely on the test line numbers to *find* the test, since |
| 154 | # we might fix multiple tests in a run. So find it by the case |
| 155 | # header. Give up if there are multiple tests with the same name. |
| 156 | test_slug = f"[case {testcase.name}]" |
| 157 | if data_lines.count(test_slug) != 1: |
| 158 | return |
| 159 | start_idx = data_lines.index(test_slug) |
| 160 | stop_idx = start_idx + 11 |
| 161 | while stop_idx < len(data_lines) and not data_lines[stop_idx].startswith("[case "): |
| 162 | stop_idx += 1 |
| 163 | |
| 164 | test = data_lines[start_idx:stop_idx] |
| 165 | out_start = test.index("[out]") |
| 166 | test[out_start + 1 :] = output |
| 167 | data_lines[start_idx:stop_idx] = test + [""] |
| 168 | data = "\n".join(data_lines) |
| 169 | |
| 170 | with open(testcase_path, "w") as f: |
| 171 | print(data, file=f) |
| 172 | |
| 173 | |
| 174 | def assert_test_output( |
no test coverage detected
searching dependent graphs…