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)
| 136 | |
| 137 | |
| 138 | def 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 | |
| 165 | def format_reachable_imports(node: MypyFile) -> list[str]: |
no test coverage detected
searching dependent graphs…