(self, testcase: DataDrivenTestCase)
| 22 | files = ["exportjson.test"] |
| 23 | |
| 24 | def run_case(self, testcase: DataDrivenTestCase) -> None: |
| 25 | error = False |
| 26 | src = "\n".join(testcase.input) |
| 27 | is_meta = testcase.name.endswith("_meta") |
| 28 | try: |
| 29 | options = Options() |
| 30 | options.use_builtins_fixtures = True |
| 31 | options.show_traceback = True |
| 32 | options.allow_empty_bodies = True |
| 33 | options.fixed_format_cache = True |
| 34 | options.sqlite_cache = False |
| 35 | fnam = os.path.join(self.base_path, "main.py") |
| 36 | with open(fnam, "w") as f: |
| 37 | f.write(src) |
| 38 | result = build.build( |
| 39 | sources=[BuildSource(fnam, "main")], options=options, alt_lib_path=test_temp_dir |
| 40 | ) |
| 41 | a = result.errors |
| 42 | error = bool(a) |
| 43 | |
| 44 | major, minor = sys.version_info[:2] |
| 45 | cache_dir = os.path.join(".mypy_cache", f"{major}.{minor}") |
| 46 | |
| 47 | for module in result.files: |
| 48 | if module in ( |
| 49 | "builtins", |
| 50 | "typing", |
| 51 | "_typeshed", |
| 52 | "__future__", |
| 53 | "typing_extensions", |
| 54 | "sys", |
| 55 | "collections", |
| 56 | ): |
| 57 | continue |
| 58 | fnam = os.path.join(cache_dir, f"{module}.data.ff") |
| 59 | if not is_meta: |
| 60 | with open(fnam, "rb") as f: |
| 61 | json_data = convert_binary_cache_to_json(f.read(), implicit_names=False) |
| 62 | else: |
| 63 | meta_fnam = os.path.join(cache_dir, f"{module}.meta.ff") |
| 64 | with open(meta_fnam, "rb") as f: |
| 65 | json_data = convert_binary_cache_meta_to_json(f.read(), fnam) |
| 66 | for line in json.dumps(json_data, indent=4).splitlines(): |
| 67 | if '"path": ' in line: |
| 68 | # The source file path is unpredictable, so filter it out |
| 69 | line = re.sub(r'"[^"]+\.pyi?"', "...", line) |
| 70 | if is_meta: |
| 71 | if '"version_id"' in line: |
| 72 | line = re.sub(r'"[0-9][^"]+"', "...", line) |
| 73 | if '"mtime"' in line or '"data_mtime"' in line: |
| 74 | line = re.sub(r": [0-9]+", ": ...", line) |
| 75 | if '"platform"' in line: |
| 76 | line = re.sub(': "[^"]+"', ": ...", line) |
| 77 | if '"hash"' not in line: |
| 78 | # Some hashes are unpredictable so filter them out |
| 79 | line = re.sub(r'"[a-f0-9]{40}"', '"<hash>"', line) |
| 80 | assert "ERROR" not in line, line |
| 81 | a.append(line) |
nothing calls this directly
no test coverage detected