|
10 | 10 | import textwrap |
11 | 11 | import unittest |
12 | 12 | from collections.abc import Callable, Iterator |
| 13 | +from pathlib import Path |
13 | 14 | from typing import Any |
14 | 15 |
|
15 | 16 | from pytest import raises |
@@ -2748,6 +2749,33 @@ def test_output(self) -> None: |
2748 | 2749 | ) |
2749 | 2750 | assert output == expected |
2750 | 2751 |
|
| 2752 | + def test_reexport_reports_import_location(self) -> None: |
| 2753 | + with use_tmp_dir(TEST_MODULE_NAME) as tmp_dir: |
| 2754 | + Path("builtins.pyi").write_text(stubtest_builtins_stub) |
| 2755 | + Path("typing.pyi").write_text(stubtest_typing_stub) |
| 2756 | + Path("enum.pyi").write_text(stubtest_enum_stub) |
| 2757 | + |
| 2758 | + os.makedirs("test_module", exist_ok=True) |
| 2759 | + Path("test_module/__init__.pyi").write_text("from .mod import f") |
| 2760 | + Path("test_module/__init__.py").write_text("from .mod import f") |
| 2761 | + Path("test_module/mod.pyi").write_text("def f(self) -> None: ...") |
| 2762 | + Path("test_module/mod.py").write_text("def f(self, x): pass") |
| 2763 | + |
| 2764 | + output = io.StringIO() |
| 2765 | + outerr = io.StringIO() |
| 2766 | + with contextlib.redirect_stdout(output), contextlib.redirect_stderr(outerr): |
| 2767 | + test_stubs(parse_options([TEST_MODULE_NAME]), use_builtins_fixtures=True) |
| 2768 | + |
| 2769 | + filtered_output = remove_color_code( |
| 2770 | + output.getvalue() |
| 2771 | + .replace(os.path.realpath(tmp_dir) + os.sep, "") |
| 2772 | + .replace(tmp_dir + os.sep, "") |
| 2773 | + ) |
| 2774 | + |
| 2775 | + assert filtered_output.count('stub does not have parameter "x"') == 1 |
| 2776 | + assert "__init__.pyi" not in filtered_output |
| 2777 | + assert "mod.py:1" in filtered_output |
| 2778 | + |
2751 | 2779 | def test_ignore_flags(self) -> None: |
2752 | 2780 | output = run_stubtest( |
2753 | 2781 | stub="", runtime="__all__ = ['f']\ndef f(): pass", options=["--ignore-missing-stub"] |
|
0 commit comments