Perform a single parser test case. The argument contains the description of the test case.
(testcase: DataDrivenTestCase)
| 33 | |
| 34 | |
| 35 | def test_parser(testcase: DataDrivenTestCase) -> None: |
| 36 | """Perform a single parser test case. |
| 37 | |
| 38 | The argument contains the description of the test case. |
| 39 | """ |
| 40 | options = Options() |
| 41 | options.hide_error_codes = True |
| 42 | |
| 43 | if testcase.file.endswith("python310.test"): |
| 44 | options.python_version = (3, 10) |
| 45 | elif testcase.file.endswith("python312.test"): |
| 46 | options.python_version = (3, 12) |
| 47 | elif testcase.file.endswith("python313.test"): |
| 48 | options.python_version = (3, 13) |
| 49 | elif testcase.file.endswith("python314.test"): |
| 50 | options.python_version = (3, 14) |
| 51 | else: |
| 52 | options.python_version = defaults.PYTHON3_VERSION |
| 53 | |
| 54 | source = "\n".join(testcase.input) |
| 55 | |
| 56 | # Apply mypy: comments to options. |
| 57 | comments = get_mypy_comments(source) |
| 58 | changes, _ = parse_mypy_comments(comments, options) |
| 59 | options = options.apply_changes(changes) |
| 60 | |
| 61 | try: |
| 62 | errors = Errors(options) |
| 63 | n = parse( |
| 64 | bytes(source, "ascii"), |
| 65 | fnam="main", |
| 66 | module="__main__", |
| 67 | errors=errors, |
| 68 | options=options, |
| 69 | file_exists=False, |
| 70 | eager=True, |
| 71 | ) |
| 72 | if errors.is_errors(): |
| 73 | errors.raise_error() |
| 74 | a = n.str_with_options(options).split("\n") |
| 75 | except CompileError as e: |
| 76 | a = e.messages |
| 77 | assert_string_arrays_equal( |
| 78 | testcase.output, a, f"Invalid parser output ({testcase.file}, line {testcase.line})" |
| 79 | ) |
| 80 | |
| 81 | |
| 82 | # The file name shown in test case output. This is displayed in error |
no test coverage detected
searching dependent graphs…