Skip to content

Commit

Permalink
Add test for issue 4248
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Apr 16, 2024
1 parent da74cb4 commit 8293a81
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions setuptools/tests/test_editable_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from setuptools.command.editable_wheel import (
_DebuggingTips,
_LinkTree,
_TopLevelFinder,
_encode_pth,
_find_virtual_namespaces,
_find_namespaces,
Expand Down Expand Up @@ -530,6 +531,49 @@ def test_combine_namespaces(self, tmp_path):
assert pkgA.a == 13
assert mod2.b == 37

def test_combine_namespaces_nested(self, tmp_path):
"""
Users may attempt to combine namespace packages in a nested way via
``package_dir`` as shown in pypa/setuptools#4248.
"""

files = {
"src": {"my_package": {"my_module.py": "a = 13"}},
"src2": {"my_package2": {"my_module2.py": "b = 37"}},
}

stack = jaraco.path.DirectoryStack()
with stack.context(tmp_path):
jaraco.path.build(files)
attrs = {
"script_name": "%PEP 517%",
"package_dir": {
"different_name": "src/my_package",
"different_name.subpkg": "src2/my_package2",
},
"packages": ["different_name", "different_name.subpkg"],
}
dist = Distribution(attrs)
finder = _TopLevelFinder(dist, str(uuid4()))
code = next(v for k, v in finder.get_implementation() if k.endswith(".py"))

with contexts.save_paths(), contexts.save_sys_modules():
for mod in attrs["packages"]:
sys.modules.pop(mod, None)

self.install_finder(code)
mod1 = import_module("different_name.my_module")
mod2 = import_module("different_name.subpkg.my_module2")

expected = str((tmp_path / "src/my_package/my_module.py").resolve())
assert str(Path(mod1.__file__).resolve()) == expected

expected = str((tmp_path / "src2/my_package2/my_module2.py").resolve())
assert str(Path(mod2.__file__).resolve()) == expected

assert mod1.a == 13
assert mod2.b == 37

def test_dynamic_path_computation(self, tmp_path):
# Follows the example in PEP 420
files = {
Expand Down

0 comments on commit 8293a81

Please sign in to comment.