Skip to content

Commit 1c56148

Browse files
authored
mypy_test.py: Remove --dry-run option (#8611)
Cf #8139.
1 parent c697a51 commit 1c56148

File tree

1 file changed

+22
-32
lines changed

1 file changed

+22
-32
lines changed

tests/mypy_test.py

+22-32
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def python_version(arg: str) -> tuple[MajorVersion, MinorVersion]:
5151

5252
class CommandLineArgs(argparse.Namespace):
5353
verbose: int
54-
dry_run: bool
5554
exclude: list[str] | None
5655
python_version: list[tuple[MajorVersion, MinorVersion]] | None
5756
dir: list[Directory] | None
@@ -61,7 +60,6 @@ class CommandLineArgs(argparse.Namespace):
6160

6261
parser = argparse.ArgumentParser(description="Test runner for typeshed. Patterns are unanchored regexps on the full path.")
6362
parser.add_argument("-v", "--verbose", action="count", default=0, help="More output")
64-
parser.add_argument("-n", "--dry-run", action="store_true", help="Don't actually run mypy")
6563
parser.add_argument("-x", "--exclude", type=str, nargs="*", help="Exclude pattern")
6664
parser.add_argument(
6765
"-p", "--python-version", type=python_version, nargs="*", action="extend", help="These versions only (major[.minor])"
@@ -89,7 +87,6 @@ class TestConfig:
8987
"""Configuration settings for a single run of the `test_typeshed` function."""
9088

9189
verbose: int
92-
dry_run: bool
9390
exclude: list[str] | None
9491
major: MajorVersion
9592
minor: MinorVersion
@@ -230,27 +227,24 @@ def run_mypy(args: TestConfig, configurations: list[MypyDistConf], files: list[s
230227
mypy_args = [*flags, *files]
231228
if args.verbose:
232229
print("running mypy", " ".join(mypy_args))
233-
if args.dry_run:
234-
exit_code = 0
230+
stdout_redirect, stderr_redirect = StringIO(), StringIO()
231+
with redirect_stdout(stdout_redirect), redirect_stderr(stderr_redirect):
232+
returned_stdout, returned_stderr, exit_code = mypy_run(mypy_args)
233+
234+
if exit_code:
235+
print_error("failure\n")
236+
captured_stdout = stdout_redirect.getvalue()
237+
captured_stderr = stderr_redirect.getvalue()
238+
if returned_stderr:
239+
print_error(returned_stderr)
240+
if captured_stderr:
241+
print_error(captured_stderr)
242+
if returned_stdout:
243+
print_error(returned_stdout)
244+
if captured_stdout:
245+
print_error(captured_stdout, end="")
235246
else:
236-
stdout_redirect, stderr_redirect = StringIO(), StringIO()
237-
with redirect_stdout(stdout_redirect), redirect_stderr(stderr_redirect):
238-
returned_stdout, returned_stderr, exit_code = mypy_run(mypy_args)
239-
240-
if exit_code:
241-
print_error("failure\n")
242-
captured_stdout = stdout_redirect.getvalue()
243-
captured_stderr = stderr_redirect.getvalue()
244-
if returned_stderr:
245-
print_error(returned_stderr)
246-
if captured_stderr:
247-
print_error(captured_stderr)
248-
if returned_stdout:
249-
print_error(returned_stdout)
250-
if captured_stdout:
251-
print_error(captured_stdout, end="")
252-
else:
253-
print_success_msg()
247+
print_success_msg()
254248
return exit_code
255249

256250

@@ -405,14 +399,11 @@ def test_the_test_cases(code: int, args: TestConfig) -> TestResults:
405399
flags = get_mypy_flags(args, None, strict=True, enforce_error_codes=False)
406400
print(f"Running mypy on the test_cases directory ({num_test_case_files} files)...")
407401
print("Running mypy " + " ".join(flags))
408-
if args.dry_run:
409-
this_code = 0
410-
else:
411-
# --warn-unused-ignores doesn't work for files inside typeshed.
412-
# SO, to work around this, we copy the test_cases directory into a TemporaryDirectory.
413-
with tempfile.TemporaryDirectory() as td:
414-
shutil.copytree(Path("test_cases"), Path(td) / "test_cases")
415-
this_code = run_mypy_as_subprocess(td, flags)
402+
# --warn-unused-ignores doesn't work for files inside typeshed.
403+
# SO, to work around this, we copy the test_cases directory into a TemporaryDirectory.
404+
with tempfile.TemporaryDirectory() as td:
405+
shutil.copytree(Path("test_cases"), Path(td) / "test_cases")
406+
this_code = run_mypy_as_subprocess(td, flags)
416407
if not this_code:
417408
print_success_msg()
418409
code = max(code, this_code)
@@ -450,7 +441,6 @@ def main() -> None:
450441
for (major, minor), platform in product(versions, platforms):
451442
config = TestConfig(
452443
verbose=args.verbose,
453-
dry_run=args.dry_run,
454444
exclude=args.exclude,
455445
major=major,
456446
minor=minor,

0 commit comments

Comments
 (0)