MCPcopy
hub / github.com/python/mypy / test_parser

Function test_parser

mypy/test/testparse.py:35–79  ·  view source on GitHub ↗

Perform a single parser test case. The argument contains the description of the test case.

(testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

33
34
35def 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

Callers 1

run_caseMethod · 0.70

Calls 14

apply_changesMethod · 0.95
is_errorsMethod · 0.95
raise_errorMethod · 0.95
OptionsClass · 0.90
get_mypy_commentsFunction · 0.90
parse_mypy_commentsFunction · 0.90
ErrorsClass · 0.90
parseFunction · 0.90
bytesClass · 0.85
splitMethod · 0.80
endswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…