Perform a single native parser test case. The argument contains the description of the test case.
(testcase: DataDrivenTestCase)
| 68 | |
| 69 | |
| 70 | def test_parser(testcase: DataDrivenTestCase) -> None: |
| 71 | """Perform a single native parser test case. |
| 72 | |
| 73 | The argument contains the description of the test case. |
| 74 | """ |
| 75 | options = Options() |
| 76 | options.hide_error_codes = True |
| 77 | |
| 78 | if testcase.file.endswith("python310.test"): |
| 79 | options.python_version = (3, 10) |
| 80 | elif testcase.file.endswith("python312.test"): |
| 81 | options.python_version = (3, 12) |
| 82 | elif testcase.file.endswith("python313.test"): |
| 83 | options.python_version = (3, 13) |
| 84 | elif testcase.file.endswith("python314.test"): |
| 85 | options.python_version = (3, 14) |
| 86 | else: |
| 87 | options.python_version = defaults.PYTHON3_VERSION |
| 88 | |
| 89 | source = "\n".join(testcase.input) |
| 90 | |
| 91 | # Apply mypy: comments to options. |
| 92 | comments = get_mypy_comments(source) |
| 93 | changes, _ = parse_mypy_comments(comments, options) |
| 94 | options = options.apply_changes(changes) |
| 95 | |
| 96 | # Check if we should skip function bodies (when ignoring errors) |
| 97 | skip_function_bodies = "# mypy: ignore-errors=True" in source |
| 98 | |
| 99 | try: |
| 100 | with temp_source(source) as fnam: |
| 101 | node, errors, type_ignores = native_parse(fnam, options, skip_function_bodies) |
| 102 | errors += load_tree(node, options) |
| 103 | node.path = "main" |
| 104 | a = node.str_with_options(options).split("\n") |
| 105 | a = [format_error(err) for err in errors] + a |
| 106 | a = [format_ignore(ignore) for ignore in type_ignores] + a |
| 107 | except CompileError as e: |
| 108 | a = e.messages |
| 109 | assert_string_arrays_equal( |
| 110 | testcase.output, a, f"Invalid parser output ({testcase.file}, line {testcase.line})" |
| 111 | ) |
| 112 | |
| 113 | |
| 114 | def format_error(err: ParseError) -> str: |
no test coverage detected
searching dependent graphs…