MCPcopy Create free account
hub / github.com/numpy/numpy / test_fail

Function test_fail

numpy/typing/tests/test_typing.py:159–191  ·  view source on GitHub ↗
(path: str)

Source from the content-addressed store, hash-verified

157@pytest.mark.skipif(NO_MYPY, reason="Mypy is not installed")
158@pytest.mark.parametrize("path", get_test_cases(FAIL_DIR))
159def test_fail(path: str) -> None:
160 __tracebackhide__ = True
161
162 with open(path) as fin:
163 lines = fin.readlines()
164
165 errors = defaultdict(lambda: "")
166
167 output_mypy = OUTPUT_MYPY
168 assert path in output_mypy
169
170 for error_line in output_mypy[path]:
171 lineno, error_line = _strip_filename(error_line)
172 errors[lineno] += f'{error_line}\n'
173
174 for i, line in enumerate(lines):
175 lineno = i + 1
176 if (
177 line.startswith('#')
178 or (" E:" not in line and lineno not in errors)
179 ):
180 continue
181
182 target_line = lines[lineno - 1]
183 if "# E:" in target_line:
184 expression, _, marker = target_line.partition(" # E: ")
185 expected_error = errors[lineno].strip()
186 marker = marker.strip()
187 _test_fail(path, expression, marker, expected_error, lineno)
188 else:
189 pytest.fail(
190 f"Unexpected mypy output at line {lineno}\n\n{errors[lineno]}"
191 )
192
193
194_FAIL_MSG1 = """Extra error at line {}

Callers

nothing calls this directly

Calls 7

openFunction · 0.85
_strip_filenameFunction · 0.85
_test_failFunction · 0.85
startswithMethod · 0.80
stripMethod · 0.80
partitionMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected