Commit d3de3353 authored by Erik Bray's avatar Erik Bray

Fixes the original root cause of #231, and re-enables the test when the...

Fixes the original root cause of #231, and re-enables the test when the tempdir is a symlink (this does not explicitly test that /tmp itself is a symlink, but the effect is the same--only one of the path levels needs to be a symlink to reproduce this isssue)
parent e0e02ba9
......@@ -2182,9 +2182,14 @@ def _handle_ns(packageName, path_item):
path = module.__path__
path.append(subpath)
loader.load_module(packageName)
# Ensure that all paths on __path__ have been run through
# normalize_path
normalized_paths = set(_normalize_cached(p) for p in module.__path__)
for path_item in path:
if path_item not in module.__path__:
module.__path__.append(path_item)
normalized = _normalize_cached(path_item)
if normalized not in normalized_paths:
module.__path__.append(normalized)
return subpath
def declare_namespace(packageName):
......
......@@ -610,18 +610,32 @@ class TestNamespaces:
def setup_method(self, method):
self._ns_pkgs = pkg_resources._namespace_packages.copy()
self._tmpdir = tempfile.mkdtemp(prefix="tests-setuptools-")
# Further, test case where the temp dir is a symlink, where applicable
# See #231
if hasattr(os, 'symlink'):
real_tmpdir = tempfile.mkdtemp(prefix="real-tests-setuptools-")
tmpdir_base, tmpdir_name = os.path.split(real_tmpdir)
tmpdir = os.path.join(tmpdir_base, tmpdir_name[5:])
os.symlink(real_tmpdir, tmpdir)
self._real_tmpdir = real_tmpdir
self._tmpdir = tmpdir
else:
tmpdir = tempfile.mkdtemp(prefix="tests-setuptools-")
self._real_tmpdir = self._tmpdir = tmpdir
os.makedirs(os.path.join(self._tmpdir, "site-pkgs"))
self._prev_sys_path = sys.path[:]
sys.path.append(os.path.join(self._tmpdir, "site-pkgs"))
def teardown_method(self, method):
shutil.rmtree(self._tmpdir)
shutil.rmtree(self._real_tmpdir)
if os.path.islink(self._tmpdir):
os.unlink(self._tmpdir)
pkg_resources._namespace_packages = self._ns_pkgs.copy()
sys.path = self._prev_sys_path[:]
@pytest.mark.skipif(os.path.islink(tempfile.gettempdir()),
reason="Test fails when /tmp is a symlink. See #231")
def test_two_levels_deep(self):
"""
Test nested namespace packages
......@@ -653,7 +667,7 @@ class TestNamespaces:
assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
# check the __path__ attribute contains both paths
expected = [
os.path.join(self._tmpdir, "site-pkgs", "pkg1", "pkg2"),
os.path.join(self._tmpdir, "site-pkgs2", "pkg1", "pkg2"),
os.path.join(self._real_tmpdir, "site-pkgs", "pkg1", "pkg2"),
os.path.join(self._real_tmpdir, "site-pkgs2", "pkg1", "pkg2"),
]
assert pkg1.pkg2.__path__ == expected
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment