Skip to content

teststubtest: assert on output without color #15292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ def run_stubtest(
output = io.StringIO()
with contextlib.redirect_stdout(output):
test_stubs(parse_options([TEST_MODULE_NAME] + options), use_builtins_fixtures=True)
# remove cwd as it's not available from outside
return (
return remove_color_code(
output.getvalue()
.replace(os.path.realpath(tmp_dir) + os.sep, "")
.replace(tmp_dir + os.sep, "")
# remove cwd as it's not available from outside
.replace(os.path.realpath(tmp_dir) + os.sep, "").replace(tmp_dir + os.sep, "")
)


Expand Down Expand Up @@ -1866,7 +1865,7 @@ def test_output(self) -> None:
f"Runtime: in file {TEST_MODULE_NAME}.py:1\ndef (num, text)\n\n"
"Found 1 error (checked 1 module)\n"
)
assert remove_color_code(output) == expected
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consolidated in run_stubtest

assert output == expected

output = run_stubtest(
stub="def bad(number: int, text: str) -> None: ...",
Expand All @@ -1877,7 +1876,7 @@ def test_output(self) -> None:
"{}.bad is inconsistent, "
'stub argument "number" differs from runtime argument "num"\n'.format(TEST_MODULE_NAME)
)
assert remove_color_code(output) == expected
assert output == expected

def test_ignore_flags(self) -> None:
output = run_stubtest(
Expand Down Expand Up @@ -1956,13 +1955,13 @@ def also_bad(asdf): pass

def test_mypy_build(self) -> None:
output = run_stubtest(stub="+", runtime="", options=[])
assert remove_color_code(output) == (
assert output == (
"error: not checking stubs due to failed mypy compile:\n{}.pyi:1: "
"error: invalid syntax [syntax]\n".format(TEST_MODULE_NAME)
)

output = run_stubtest(stub="def f(): ...\ndef f(): ...", runtime="", options=[])
assert remove_color_code(output) == (
assert output == (
"error: not checking stubs due to mypy build errors:\n{}.pyi:2: "
'error: Name "f" already defined on line 1 [no-redef]\n'.format(TEST_MODULE_NAME)
)
Expand Down Expand Up @@ -2019,7 +2018,7 @@ def test_config_file(self) -> None:
stub = "from decimal import Decimal\ntemp: Decimal\n"
config_file = f"[mypy]\nplugins={root_dir}/test-data/unit/plugins/decimal_to_int.py\n"
output = run_stubtest(stub=stub, runtime=runtime, options=[])
assert remove_color_code(output) == (
assert output == (
f"error: {TEST_MODULE_NAME}.temp variable differs from runtime type Literal[5]\n"
f"Stub: in file {TEST_MODULE_NAME}.pyi:2\n_decimal.Decimal\nRuntime:\n5\n\n"
"Found 1 error (checked 1 module)\n"
Expand Down