From 0d4c84ada1ffd25f63ca0c6072ffe6f0f73a8667 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 21 Oct 2026 22:03:45 -0700 Subject: [PATCH 1/2] [mypyc] make --update-data work for mypyc tests Authored by Codex --- mypyc/test/test_run.py | 2 +- mypyc/test/testutil.py | 33 ++++----------------------------- 2 files changed, 5 insertions(+), 30 deletions(-) diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index 55923dfae3aa2..50680a9348c1f 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py @@ -440,7 +440,7 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) -> outlines = [ fix_native_line_number(line, testcase.file, testcase.line) for line in outlines ] - assert_test_output(testcase, outlines, msg, expected) + assert_test_output(testcase, outlines, msg, expected, incremental_step=incremental_step) if incremental_step > 1 and options.incremental: suffix = "" if incremental_step == 2 else str(incremental_step - 1) diff --git a/mypyc/test/testutil.py b/mypyc/test/testutil.py index cf56d769931d5..a6f7c600a87e5 100644 --- a/mypyc/test/testutil.py +++ b/mypyc/test/testutil.py @@ -18,6 +18,7 @@ from mypy.test.config import test_temp_dir from mypy.test.data import DataDrivenTestCase, DataSuite from mypy.test.helpers import assert_string_arrays_equal +from mypy.test.update_data import update_testcase_output from mypy.types import Type from mypyc.analysis.ircheck import assert_func_ir_valid from mypyc.common import IS_32_BIT_PLATFORM, PLATFORM_SIZE @@ -153,46 +154,20 @@ def build_ir_for_single_file2( return module, tree, result.types, mapper -def update_testcase_output(testcase: DataDrivenTestCase, output: list[str]) -> None: - # TODO: backport this to mypy - assert testcase.old_cwd is not None, "test was not properly set up" - testcase_path = os.path.join(testcase.old_cwd, testcase.file) - with open(testcase_path) as f: - data_lines = f.read().splitlines() - - # We can't rely on the test line numbers to *find* the test, since - # we might fix multiple tests in a run. So find it by the case - # header. Give up if there are multiple tests with the same name. - test_slug = f"[case {testcase.name}]" - if data_lines.count(test_slug) != 1: - return - start_idx = data_lines.index(test_slug) - stop_idx = start_idx + 11 - while stop_idx < len(data_lines) and not data_lines[stop_idx].startswith("[case "): - stop_idx += 1 - - test = data_lines[start_idx:stop_idx] - out_start = test.index("[out]") - test[out_start + 1 :] = output - data_lines[start_idx:stop_idx] = test + [""] - data = "\n".join(data_lines) - - with open(testcase_path, "w") as f: - print(data, file=f) - - def assert_test_output( testcase: DataDrivenTestCase, actual: list[str], message: str, expected: list[str] | None = None, formatted: list[str] | None = None, + *, + incremental_step: int = 1, ) -> None: __tracebackhide__ = True expected_output = expected if expected is not None else testcase.output if expected_output != actual and testcase.config.getoption("--update-data", False): - update_testcase_output(testcase, actual) + update_testcase_output(testcase, actual, incremental_step=incremental_step) assert_string_arrays_equal( expected_output, actual, f"{message} ({testcase.file}, line {testcase.line})" From 3fc9723eb8519dcdd3bc05cd7e038be90f879074 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 Oct 2026 05:05:47 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypyc/test/test_run.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index 50680a9348c1f..217c8f9446ac8 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py @@ -440,7 +440,9 @@ def run_case_step(self, testcase: DataDrivenTestCase, incremental_step: int) -> outlines = [ fix_native_line_number(line, testcase.file, testcase.line) for line in outlines ] - assert_test_output(testcase, outlines, msg, expected, incremental_step=incremental_step) + assert_test_output( + testcase, outlines, msg, expected, incremental_step=incremental_step + ) if incremental_step > 1 and options.incremental: suffix = "" if incremental_step == 2 else str(incremental_step - 1)