Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(
:param runtime_desc: Specialised description for the runtime object, should you wish

"""
self.object_path = object_path
self.object_desc = ".".join(object_path)
self.message = message
self.stub_object = stub_object
Expand All @@ -116,10 +117,12 @@ def get_description(self, concise: bool = False) -> str:
return _style(self.object_desc, bold=True) + " " + self.message

stub_line = None
stub_file: None = None
stub_file = None
if not isinstance(self.stub_object, Missing):
stub_line = self.stub_object.line
# TODO: Find a way of getting the stub file
stub_node = get_stub(self.object_path[0])
if stub_node is not None:
stub_file = stub_node.path or None

stub_loc_str = ""
if stub_line:
Expand Down
11 changes: 8 additions & 3 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ def run_stubtest(
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 output.getvalue().replace(tmp_dir + os.sep, "")
return (
output.getvalue()
.replace(os.path.realpath(tmp_dir) + os.sep, "")
.replace(tmp_dir + os.sep, "")
)


class Case:
Expand Down Expand Up @@ -1274,7 +1278,8 @@ def test_output(self) -> None:
expected = (
f'error: {TEST_MODULE_NAME}.bad is inconsistent, stub argument "number" differs '
'from runtime argument "num"\n'
"Stub: at line 1\ndef (number: builtins.int, text: builtins.str)\n"
f"Stub: at line 1 in file {TEST_MODULE_NAME}.pyi\n"
"def (number: builtins.int, text: builtins.str)\n"
f"Runtime: at line 1 in file {TEST_MODULE_NAME}.py\ndef (num, text)\n\n"
"Found 1 error (checked 1 module)\n"
)
Expand Down Expand Up @@ -1432,7 +1437,7 @@ def test_config_file(self) -> None:
output = run_stubtest(stub=stub, runtime=runtime, options=[])
assert remove_color_code(output) == (
f"error: {TEST_MODULE_NAME}.temp variable differs from runtime type Literal[5]\n"
"Stub: at line 2\n_decimal.Decimal\nRuntime:\n5\n\n"
f"Stub: at line 2 in file {TEST_MODULE_NAME}.pyi\n_decimal.Decimal\nRuntime:\n5\n\n"
"Found 1 error (checked 1 module)\n"
)
output = run_stubtest(stub=stub, runtime=runtime, options=[], config_file=config_file)
Expand Down