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

Method run_case

mypyc/test/test_annotate.py:30–71  ·  view source on GitHub ↗

Perform a runtime checking transformation test case.

(self, testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

28 optional_out = True
29
30 def run_case(self, testcase: DataDrivenTestCase) -> None:
31 """Perform a runtime checking transformation test case."""
32 options = infer_ir_build_options_from_test_name(testcase.name)
33 if options is None:
34 # Skipped test case
35 return
36 with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
37 expected_output = remove_comment_lines(testcase.output)
38
39 # Parse "# A: <message>" comments.
40 for i, line in enumerate(testcase.input):
41 if "# A:" in line:
42 msg = line.rpartition("# A:")[2].strip()
43 expected_output.append(f"main:{i + 1}: {msg}")
44
45 ir = None
46 try:
47 ir, tree, type_map, mapper = build_ir_for_single_file2(testcase.input, options)
48 except CompileError as e:
49 actual = e.messages
50 else:
51 annotations = generate_annotations("native.py", tree, ir, type_map, mapper)
52 actual = []
53 for line_num, line_anns in sorted(
54 annotations.annotations.items(), key=lambda it: it[0]
55 ):
56 anns = get_max_prio(line_anns)
57 str_anns = [a.message for a in anns]
58 s = " ".join(str_anns)
59 actual.append(f"main:{line_num}: {s}")
60
61 try:
62 assert_test_output(testcase, actual, "Invalid source code output", expected_output)
63 except BaseException:
64 if ir:
65 print("Generated IR:\n")
66 for fn in ir.functions:
67 if fn.name == "__top_level__":
68 continue
69 for s in format_func(fn):
70 print(s)
71 raise

Callers

nothing calls this directly

Calls 15

use_custom_builtinsFunction · 0.90
remove_comment_linesFunction · 0.90
generate_annotationsFunction · 0.90
get_max_prioFunction · 0.90
assert_test_outputFunction · 0.90
format_funcFunction · 0.90
enumerateFunction · 0.85
sortedFunction · 0.85
printFunction · 0.85
stripMethod · 0.80

Tested by

no test coverage detected