(self, testcase: DataDrivenTestCase)
| 21 | files = ["typexport-basic.test"] |
| 22 | |
| 23 | def run_case(self, testcase: DataDrivenTestCase) -> None: |
| 24 | try: |
| 25 | line = testcase.input[0] |
| 26 | mask = "" |
| 27 | if line.startswith("##"): |
| 28 | mask = "(" + line[2:].strip() + ")$" |
| 29 | |
| 30 | src = "\n".join(testcase.input) |
| 31 | options = Options() |
| 32 | options.strict_optional = False # TODO: Enable strict optional checking |
| 33 | options.use_builtins_fixtures = True |
| 34 | options.show_traceback = True |
| 35 | options.export_types = True |
| 36 | options.preserve_asts = True |
| 37 | options.allow_empty_bodies = True |
| 38 | options.reveal_verbose_types = True |
| 39 | result = build.build( |
| 40 | sources=[BuildSource("main", None, src)], |
| 41 | options=options, |
| 42 | alt_lib_path=test_temp_dir, |
| 43 | ) |
| 44 | a = result.errors |
| 45 | map = result.types |
| 46 | nodes = map.keys() |
| 47 | |
| 48 | # Ignore NameExpr nodes of variables with explicit (trivial) types |
| 49 | # to simplify output. |
| 50 | searcher = SkippedNodeSearcher() |
| 51 | for file in result.files.values(): |
| 52 | searcher.ignore_file = file.fullname not in testcase.test_modules |
| 53 | file.accept(searcher) |
| 54 | ignored = searcher.nodes |
| 55 | |
| 56 | # Filter nodes that should be included in the output. |
| 57 | keys = [] |
| 58 | for node in nodes: |
| 59 | if isinstance(node, TempNode): |
| 60 | continue |
| 61 | if node.line != -1 and map[node]: |
| 62 | if ignore_node(node) or node in ignored: |
| 63 | continue |
| 64 | if re.match(mask, short_type(node)) or ( |
| 65 | isinstance(node, NameExpr) and re.match(mask, node.name) |
| 66 | ): |
| 67 | # Include node in output. |
| 68 | keys.append(node) |
| 69 | |
| 70 | for key in sorted( |
| 71 | keys, |
| 72 | key=lambda n: (n.line, short_type(n), str(n) + map[n].str_with_options(options)), |
| 73 | ): |
| 74 | ts = map[key].str_with_options(options).replace("*", "") # Remove erased tags |
| 75 | ts = ts.replace("__main__.", "") |
| 76 | a.append(f"{short_type(key)}({key.line}) : {ts}") |
| 77 | except CompileError as e: |
| 78 | a = e.messages |
| 79 | assert_string_arrays_equal( |
| 80 | testcase.output, |
nothing calls this directly
no test coverage detected