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

Method run_case

mypy/test/testmerge.py:49–95  ·  view source on GitHub ↗
(self, testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

47 self.type_str_conv = TypeStrVisitor(self.id_mapper, options=Options())
48
49 def run_case(self, testcase: DataDrivenTestCase) -> None:
50 name = testcase.name
51 # We use the test case name to decide which data structures to dump.
52 # Dumping everything would result in very verbose test cases.
53 if name.endswith("_symtable"):
54 kind = SYMTABLE
55 elif name.endswith("_typeinfo"):
56 kind = TYPEINFO
57 elif name.endswith("_types"):
58 kind = TYPES
59 else:
60 kind = AST
61
62 main_src = "\n".join(testcase.input)
63 result = self.build(main_src, testcase)
64 assert result is not None, "cases where CompileError occurred should not be run"
65 result.manager.fscache.flush()
66 fine_grained_manager = FineGrainedBuildManager(result)
67
68 a = []
69 if result.errors:
70 a.extend(result.errors)
71
72 target_path = os.path.join(test_temp_dir, "target.py")
73 shutil.copy(os.path.join(test_temp_dir, "target.py.next"), target_path)
74
75 a.extend(self.dump(fine_grained_manager, kind, testcase.test_modules))
76 old_subexpr = get_subexpressions(result.manager.modules["target"])
77
78 a.append("==>")
79
80 new_file, new_types = self.build_increment(fine_grained_manager, "target", target_path)
81 a.extend(self.dump(fine_grained_manager, kind, testcase.test_modules))
82
83 for expr in old_subexpr:
84 if isinstance(expr, TypeVarExpr):
85 # These are merged so we can't perform the check.
86 continue
87 # Verify that old AST nodes are removed from the expression type map.
88 assert expr not in new_types
89
90 if testcase.normalize_output:
91 a = normalize_error_messages(a)
92
93 assert_string_arrays_equal(
94 testcase.output, a, f"Invalid output ({testcase.file}, line {testcase.line})"
95 )
96
97 def build(self, source: str, testcase: DataDrivenTestCase) -> BuildResult | None:
98 options = parse_options(source, testcase, incremental_step=1)

Callers

nothing calls this directly

Calls 14

buildMethod · 0.95
dumpMethod · 0.95
build_incrementMethod · 0.95
get_subexpressionsFunction · 0.90
normalize_error_messagesFunction · 0.90
isinstanceFunction · 0.85
extendMethod · 0.80
appendMethod · 0.80
endswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected