(self, testcase: DataDrivenTestCase)
| 31 | optional_out = True |
| 32 | |
| 33 | def run_case(self, testcase: DataDrivenTestCase) -> None: |
| 34 | # Parse options from test case description (arguments must not have spaces) |
| 35 | text = "\n".join(testcase.input) |
| 36 | m = re.search(r"# *cmd: *(.*)", text) |
| 37 | assert m is not None, 'Test case missing "# cmd: <files>" section' |
| 38 | args = m.group(1).split() |
| 39 | |
| 40 | # Write main program to run (not compiled) |
| 41 | program = "_%s.py" % testcase.name |
| 42 | program_path = os.path.join(test_temp_dir, program) |
| 43 | with open(program_path, "w") as f: |
| 44 | f.write(text) |
| 45 | |
| 46 | env = os.environ.copy() |
| 47 | env["PYTHONPATH"] = base_path |
| 48 | |
| 49 | out = b"" |
| 50 | try: |
| 51 | # Compile program |
| 52 | cmd = subprocess.run( |
| 53 | [sys.executable, "-m", "mypyc", *args], |
| 54 | stdout=subprocess.PIPE, |
| 55 | stderr=subprocess.STDOUT, |
| 56 | cwd="tmp", |
| 57 | env=env, |
| 58 | ) |
| 59 | if "ErrorOutput" in testcase.name or cmd.returncode != 0: |
| 60 | out += cmd.stdout |
| 61 | elif "WarningOutput" in testcase.name: |
| 62 | # Strip out setuptools build related output since we're only |
| 63 | # interested in the messages emitted during compilation. |
| 64 | messages, _, _ = cmd.stdout.partition(b"running build_ext") |
| 65 | out += messages |
| 66 | |
| 67 | if cmd.returncode == 0: |
| 68 | # Run main program |
| 69 | out += subprocess.check_output([python3_path, program], cwd="tmp") |
| 70 | finally: |
| 71 | suffix = "pyd" if sys.platform == "win32" else "so" |
| 72 | so_paths = glob.glob(f"tmp/**/*.{suffix}", recursive=True) |
| 73 | for path in so_paths: |
| 74 | os.remove(path) |
| 75 | |
| 76 | # Strip out 'tmp/' from error message paths in the testcase output, |
| 77 | # due to a mismatch between this test and mypy's test suite. |
| 78 | expected = [x.replace("tmp/", "") for x in testcase.output] |
| 79 | |
| 80 | # Verify output |
| 81 | actual = normalize_error_messages(out.decode().splitlines()) |
| 82 | assert_test_output(testcase, actual, "Invalid output", expected=expected) |
nothing calls this directly
no test coverage detected