Commit 39787939 authored by Jason R. Coombs's avatar Jason R. Coombs

Use py.path objects for cleaner setup

parent e3d73340
...@@ -653,21 +653,17 @@ class TestNamespaces: ...@@ -653,21 +653,17 @@ class TestNamespaces:
Check both are in the _namespace_packages dict and that their __path__ Check both are in the _namespace_packages dict and that their __path__
is correct is correct
""" """
real_tmpdir = str(symlinked_tmpdir.realpath()) real_tmpdir = symlinked_tmpdir.realpath()
tmpdir = str(symlinked_tmpdir) tmpdir = symlinked_tmpdir
sys.path.append(os.path.join(tmpdir, "site-pkgs2")) sys.path.append(str(tmpdir / 'site-pkgs2'))
os.makedirs(os.path.join(tmpdir, "site-pkgs", "pkg1", "pkg2")) site_dirs = tmpdir / 'site-pkgs', tmpdir / 'site-pkgs2'
os.makedirs(os.path.join(tmpdir, "site-pkgs2", "pkg1", "pkg2"))
ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n" ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n"
for site in ["site-pkgs", "site-pkgs2"]: for site in site_dirs:
pkg1_init = open(os.path.join(tmpdir, site, pkg1 = site / 'pkg1'
"pkg1", "__init__.py"), "w") pkg2 = pkg1 / 'pkg2'
pkg1_init.write(ns_str) pkg2.ensure_dir()
pkg1_init.close() (pkg1 / '__init__.py').write_text(ns_str, encoding='utf-8')
pkg2_init = open(os.path.join(tmpdir, site, (pkg2 / '__init__.py').write_text(ns_str, encoding='utf-8')
"pkg1", "pkg2", "__init__.py"), "w")
pkg2_init.write(ns_str)
pkg2_init.close()
import pkg1 import pkg1
assert "pkg1" in pkg_resources._namespace_packages assert "pkg1" in pkg_resources._namespace_packages
# attempt to import pkg2 from site-pkgs2 # attempt to import pkg2 from site-pkgs2
...@@ -677,8 +673,8 @@ class TestNamespaces: ...@@ -677,8 +673,8 @@ class TestNamespaces:
assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"] assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
# check the __path__ attribute contains both paths # check the __path__ attribute contains both paths
expected = [ expected = [
os.path.join(real_tmpdir, "site-pkgs", "pkg1", "pkg2"), str(real_tmpdir / "site-pkgs" / "pkg1" / "pkg2"),
os.path.join(real_tmpdir, "site-pkgs2", "pkg1", "pkg2"), str(real_tmpdir / "site-pkgs2" / "pkg1" / "pkg2"),
] ]
assert pkg1.pkg2.__path__ == expected 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