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

Function test_transform

mypy/test/testtransform.py:32–64  ·  view source on GitHub ↗

Perform an identity transform test case.

(testcase: DataDrivenTestCase)

Source from the content-addressed store, hash-verified

30
31
32def test_transform(testcase: DataDrivenTestCase) -> None:
33 """Perform an identity transform test case."""
34
35 try:
36 src = "\n".join(testcase.input)
37 options = parse_options(src, testcase, 1)
38 options.use_builtins_fixtures = True
39 options.semantic_analysis_only = True
40 options.show_traceback = True
41 options.reveal_verbose_types = True
42 result = build.build(
43 sources=[BuildSource("main", None, src)], options=options, alt_lib_path=test_temp_dir
44 )
45 a = result.errors
46 if a:
47 raise CompileError(a)
48 # Include string representations of the source files in the actual
49 # output.
50 for module in sorted(result.files.keys()):
51 if module in testcase.test_modules:
52 t = TypeAssertTransformVisitor()
53 t.test_only = True
54 file = t.mypyfile(result.files[module])
55 a += file.str_with_options(options).split("\n")
56 except CompileError as e:
57 a = e.messages
58 if testcase.normalize_output:
59 a = normalize_error_messages(a)
60 assert_string_arrays_equal(
61 testcase.output,
62 a,
63 f"Invalid semantic analyzer output ({testcase.file}, line {testcase.line})",
64 )

Callers 1

run_caseMethod · 0.85

Calls 13

parse_optionsFunction · 0.90
BuildSourceClass · 0.90
CompileErrorClass · 0.90
normalize_error_messagesFunction · 0.90
sortedFunction · 0.85
keysMethod · 0.80
mypyfileMethod · 0.80
splitMethod · 0.80
joinMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…