MCPcopy Index your code
hub / github.com/python/mypy / update_testcase_output

Function update_testcase_output

mypyc/test/testutil.py:146–171  ·  view source on GitHub ↗
(testcase: DataDrivenTestCase, output: list[str])

Source from the content-addressed store, hash-verified

144
145
146def 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
174def assert_test_output(

Callers 1

assert_test_outputFunction · 0.70

Calls 8

lenFunction · 0.85
printFunction · 0.85
splitlinesMethod · 0.80
indexMethod · 0.80
joinMethod · 0.45
readMethod · 0.45
countMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…