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

Function test_parser_imports

mypy/test/test_nativeparse.py:138–162  ·  view source on GitHub ↗

Perform a single native parser imports test case. The argument contains the description of the test case. This test outputs only reachable import information.

(testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

136
137
138def test_parser_imports(testcase: DataDrivenTestCase) -> None:
139 """Perform a single native parser imports test case.
140
141 The argument contains the description of the test case.
142 This test outputs only reachable import information.
143 """
144 options = Options()
145 options.hide_error_codes = True
146 options.python_version = (3, 10)
147
148 source = "\n".join(testcase.input)
149
150 try:
151 with temp_source(source) as fnam:
152 node, errors, type_ignores = native_parse(fnam, options)
153 errors += load_tree(node, options)
154 # Extract and format reachable imports
155 a = format_reachable_imports(node)
156 a = [format_error(err) for err in errors] + a
157 except CompileError as e:
158 a = e.messages
159
160 assert_string_arrays_equal(
161 testcase.output, a, f"Invalid parser output ({testcase.file}, line {testcase.line})"
162 )
163
164
165def format_reachable_imports(node: MypyFile) -> list[str]:

Callers 1

run_caseMethod · 0.85

Calls 8

OptionsClass · 0.90
native_parseFunction · 0.90
temp_sourceFunction · 0.85
load_treeFunction · 0.85
format_reachable_importsFunction · 0.85
format_errorFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…