From ee0519efe6b3404981b4871b4fb1767ba4bdd9a5 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Thu, 25 Aug 2022 13:05:05 +0100 Subject: [PATCH 1/2] `mypy_test.py`: Remove `--dry-run` option --- tests/mypy_test.py | 55 +++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index ed84a9da3c4b..3c70d3b605ca 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -51,7 +51,6 @@ def python_version(arg: str) -> tuple[MajorVersion, MinorVersion]: class CommandLineArgs(argparse.Namespace): verbose: int - dry_run: bool exclude: list[str] | None python_version: list[tuple[MajorVersion, MinorVersion]] | None dir: list[Directory] | None @@ -61,7 +60,6 @@ class CommandLineArgs(argparse.Namespace): parser = argparse.ArgumentParser(description="Test runner for typeshed. Patterns are unanchored regexps on the full path.") parser.add_argument("-v", "--verbose", action="count", default=0, help="More output") -parser.add_argument("-n", "--dry-run", action="store_true", help="Don't actually run mypy") parser.add_argument("-x", "--exclude", type=str, nargs="*", help="Exclude pattern") parser.add_argument( "-p", "--python-version", type=python_version, nargs="*", action="extend", help="These versions only (major[.minor])" @@ -87,9 +85,7 @@ class CommandLineArgs(argparse.Namespace): @dataclass class TestConfig: """Configuration settings for a single run of the `test_typeshed` function.""" - verbose: int - dry_run: bool exclude: list[str] | None major: MajorVersion minor: MinorVersion @@ -230,27 +226,24 @@ def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[s mypy_args = [*flags, *files] if args.verbose: print("running mypy", " ".join(mypy_args)) - if args.dry_run: - exit_code = 0 + stdout_redirect, stderr_redirect = StringIO(), StringIO() + with redirect_stdout(stdout_redirect), redirect_stderr(stderr_redirect): + returned_stdout, returned_stderr, exit_code = mypy_run(mypy_args) + + if exit_code: + print_error("failure\n") + captured_stdout = stdout_redirect.getvalue() + captured_stderr = stderr_redirect.getvalue() + if returned_stderr: + print_error(returned_stderr) + if captured_stderr: + print_error(captured_stderr) + if returned_stdout: + print_error(returned_stdout) + if captured_stdout: + print_error(captured_stdout, end="") else: - stdout_redirect, stderr_redirect = StringIO(), StringIO() - with redirect_stdout(stdout_redirect), redirect_stderr(stderr_redirect): - returned_stdout, returned_stderr, exit_code = mypy_run(mypy_args) - - if exit_code: - print_error("failure\n") - captured_stdout = stdout_redirect.getvalue() - captured_stderr = stderr_redirect.getvalue() - if returned_stderr: - print_error(returned_stderr) - if captured_stderr: - print_error(captured_stderr) - if returned_stdout: - print_error(returned_stdout) - if captured_stdout: - print_error(captured_stdout, end="") - else: - print_success_msg() + print_success_msg() return exit_code @@ -405,14 +398,11 @@ def test_the_test_cases(code: int, args: TestConfig) -> TestResults: flags = get_mypy_flags(args, None, strict=True, enforce_error_codes=False) print(f"Running mypy on the test_cases directory ({num_test_case_files} files)...") print("Running mypy " + " ".join(flags)) - if args.dry_run: - this_code = 0 - else: - # --warn-unused-ignores doesn't work for files inside typeshed. - # SO, to work around this, we copy the test_cases directory into a TemporaryDirectory. - with tempfile.TemporaryDirectory() as td: - shutil.copytree(Path("test_cases"), Path(td) / "test_cases") - this_code = run_mypy_as_subprocess(td, flags) + # --warn-unused-ignores doesn't work for files inside typeshed. + # SO, to work around this, we copy the test_cases directory into a TemporaryDirectory. + with tempfile.TemporaryDirectory() as td: + shutil.copytree(Path("test_cases"), Path(td) / "test_cases") + this_code = run_mypy_as_subprocess(td, flags) if not this_code: print_success_msg() code = max(code, this_code) @@ -450,7 +440,6 @@ def main() -> None: for (major, minor), platform in product(versions, platforms): config = TestConfig( verbose=args.verbose, - dry_run=args.dry_run, exclude=args.exclude, major=major, minor=minor, From a06d15c6222b2b635f163da8ce4ad3cbfe72d271 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 12:11:56 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks --- tests/mypy_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 3c70d3b605ca..b5c5e88a77ec 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -85,6 +85,7 @@ class CommandLineArgs(argparse.Namespace): @dataclass class TestConfig: """Configuration settings for a single run of the `test_typeshed` function.""" + verbose: int exclude: list[str] | None major: MajorVersion