Skip to content

Commit 14b242f

Browse files
authored
🧪 Add a test for implicit ns src root lookup (#10171)
This patch modifies the `test_discover_package_path_source_root_as_*` tests to also run against directory layouts with no exlicitly existing `__init__.py` file. They were added in #10036 and seem to be insufficient, not covering PEP 420 implicit namespaces.
1 parent 6456374 commit 14b242f

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/pyreverse/test_main.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,15 @@ def test_project_root_in_sys_path() -> None:
6565
assert sys.path == [PROJECT_ROOT_DIR]
6666

6767

68-
def test_discover_package_path_source_root_as_parent(tmp_path: Any) -> None:
68+
@pytest.mark.parametrize(
69+
"py_mod_base_name",
70+
("__init__", "impl"),
71+
ids=("explicit-namespace", "implicit-namespace"),
72+
)
73+
def test_discover_package_path_source_root_as_parent(
74+
py_mod_base_name: str,
75+
tmp_path: Any,
76+
) -> None:
6977
"""Test discover_package_path when source root is a parent of the module."""
7078
# Create this temporary structure:
7179
# /tmp_path/
@@ -75,14 +83,22 @@ def test_discover_package_path_source_root_as_parent(tmp_path: Any) -> None:
7583
project_dir = tmp_path / "project"
7684
package_dir = project_dir / "mypackage"
7785
package_dir.mkdir(parents=True)
78-
(package_dir / "__init__.py").touch()
86+
(package_dir / f"{py_mod_base_name}.py").touch()
7987

8088
# Test with project_dir as source root (parent of package)
8189
result = discover_package_path(str(package_dir), [str(project_dir)])
8290
assert result == str(project_dir)
8391

8492

85-
def test_discover_package_path_source_root_as_child(tmp_path: Any) -> None:
93+
@pytest.mark.parametrize(
94+
"py_mod_base_name",
95+
("__init__", "impl"),
96+
ids=("explicit-namespace", "implicit-namespace"),
97+
)
98+
def test_discover_package_path_source_root_as_child(
99+
py_mod_base_name: str,
100+
tmp_path: Any,
101+
) -> None:
86102
"""Test discover_package_path when source root is a child of the module."""
87103
# Create this temporary structure:
88104
# /tmp_path/
@@ -94,7 +110,7 @@ def test_discover_package_path_source_root_as_child(tmp_path: Any) -> None:
94110
src_dir = project_dir / "src"
95111
package_dir = src_dir / "mypackage"
96112
package_dir.mkdir(parents=True)
97-
(package_dir / "__init__.py").touch()
113+
(package_dir / f"{py_mod_base_name}.py").touch()
98114

99115
# Test with src_dir as source root (child of project)
100116
result = discover_package_path(str(project_dir), [str(src_dir)])

0 commit comments

Comments
 (0)