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

Method run_case

mypyc/test/test_analysis.py:32–77  ·  view source on GitHub ↗

Perform a data-flow analysis test case.

(self, testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

30 optional_out = True
31
32 def run_case(self, testcase: DataDrivenTestCase) -> None:
33 """Perform a data-flow analysis test case."""
34
35 with use_custom_builtins(os.path.join(self.data_prefix, ICODE_GEN_BUILTINS), testcase):
36 try:
37 ir = build_ir_for_single_file(testcase.input)
38 except CompileError as e:
39 actual = e.messages
40 else:
41 actual = []
42 for fn in ir:
43 if fn.name == TOP_LEVEL_NAME and not testcase.name.endswith("_toplevel"):
44 continue
45 exceptions.insert_exception_handling(fn, True)
46 actual.extend(format_func(fn))
47 cfg = dataflow.get_cfg(fn.blocks)
48 args: set[Value] = set(fn.arg_regs)
49 name = testcase.name
50 if name.endswith("_MaybeDefined"):
51 # Forward, maybe
52 analysis_result = dataflow.analyze_maybe_defined_regs(fn.blocks, cfg, args)
53 elif name.endswith("_Liveness"):
54 # Backward, maybe
55 analysis_result = dataflow.analyze_live_regs(fn.blocks, cfg)
56 elif name.endswith("_MustDefined"):
57 # Forward, must
58 analysis_result = dataflow.analyze_must_defined_regs(
59 fn.blocks, cfg, args, regs=all_values(fn.arg_regs, fn.blocks)
60 )
61 elif name.endswith("_BorrowedArgument"):
62 # Forward, must
63 analysis_result = dataflow.analyze_borrowed_arguments(fn.blocks, cfg, args)
64 else:
65 assert False, "No recognized _AnalysisName suffix in test case"
66
67 names = generate_names_for_ir(fn.arg_regs, fn.blocks)
68
69 for key in sorted(
70 analysis_result.before.keys(), key=lambda x: (x[0].label, x[1])
71 ):
72 pre = ", ".join(sorted(names[reg] for reg in analysis_result.before[key]))
73 post = ", ".join(sorted(names[reg] for reg in analysis_result.after[key]))
74 actual.append(
75 "%-8s %-23s %s" % ((key[0].label, key[1]), "{%s}" % pre, "{%s}" % post)
76 )
77 assert_test_output(testcase, actual, "Invalid source code output")

Callers

nothing calls this directly

Calls 13

use_custom_builtinsFunction · 0.90
build_ir_for_single_fileFunction · 0.90
format_funcFunction · 0.90
all_valuesFunction · 0.90
generate_names_for_irFunction · 0.90
assert_test_outputFunction · 0.90
setClass · 0.85
sortedFunction · 0.85
extendMethod · 0.80
keysMethod · 0.80
appendMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected