Skip to content

Commit a39d362

Browse files
committed
Add test for issue 4248
1 parent 153d75e commit a39d362

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

setuptools/tests/test_editable_install.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from setuptools.command.editable_wheel import (
2525
_DebuggingTips,
2626
_LinkTree,
27+
_TopLevelFinder,
2728
_encode_pth,
2829
_find_virtual_namespaces,
2930
_find_namespaces,
@@ -530,6 +531,49 @@ def test_combine_namespaces(self, tmp_path):
530531
assert pkgA.a == 13
531532
assert mod2.b == 37
532533

534+
def test_combine_namespaces_nested(self, tmp_path):
535+
"""
536+
Users may attempt to combine namespace packages in a nested way via
537+
``package_dir`` as shown in pypa/setuptools#4248.
538+
"""
539+
540+
files = {
541+
"src": {"my_package": {"my_module.py": "a = 13"}},
542+
"src2": {"my_package2": {"my_module2.py": "b = 37"}},
543+
}
544+
545+
stack = jaraco.path.DirectoryStack()
546+
with stack.context(tmp_path):
547+
jaraco.path.build(files)
548+
attrs = {
549+
"script_name": "%PEP 517%",
550+
"package_dir": {
551+
"different_name": "src/my_package",
552+
"different_name.subpkg": "src2/my_package2",
553+
},
554+
"packages": ["different_name", "different_name.subpkg"],
555+
}
556+
dist = Distribution(attrs)
557+
finder = _TopLevelFinder(dist, str(uuid4()))
558+
code = next(v for k, v in finder.get_implementation() if k.endswith(".py"))
559+
560+
with contexts.save_paths(), contexts.save_sys_modules():
561+
for mod in attrs["packages"]:
562+
sys.modules.pop(mod, None)
563+
564+
self.install_finder(code)
565+
mod1 = import_module("different_name.my_module")
566+
mod2 = import_module("different_name.subpkg.my_module2")
567+
568+
expected = str((tmp_path / "src/my_package/my_module.py").resolve())
569+
assert str(Path(mod1.__file__).resolve()) == expected
570+
571+
expected = str((tmp_path / "src2/my_package2/my_module2.py").resolve())
572+
assert str(Path(mod2.__file__).resolve()) == expected
573+
574+
assert mod1.a == 13
575+
assert mod2.b == 37
576+
533577
def test_dynamic_path_computation(self, tmp_path):
534578
# Follows the example in PEP 420
535579
files = {

0 commit comments

Comments
 (0)