diff options
| author | Erik Bray <embray@stsci.edu> | 2016-01-06 17:08:56 -0500 |
|---|---|---|
| committer | Erik Bray <embray@stsci.edu> | 2016-01-06 17:08:56 -0500 |
| commit | ebc54982b1085b05054a75dbcdd16008ac20a60e (patch) | |
| tree | 33f3ea738d119769cc8ec7be1b9c433edffc001a /pkg_resources/tests/test_resources.py | |
| parent | d3de33538948081d9ef39168fde870c977e30115 (diff) | |
| download | python-setuptools-git-ebc54982b1085b05054a75dbcdd16008ac20a60e.tar.gz | |
Sort __path__ entries for namespace packages according to their order
in sys.path. This ensures that lookups in __path__ will be the same
as sys.path resolution.
This also adds a replace argument to Distribution.insert_on meant
to be used with the replace argumen to WorkingSet.add. This ensures
that new sys.path entries added via WorkingSet.add are inserted at
the beginning, rather than appended to the end. This is necessary
for consistency with the above change, and kind of makes more sense
anyways. This means that if a Distribution is added to a WorkingSet,
that replaces a different version of that Distribution, the new version
of that Distribution will have its location first on sys.path.
Diffstat (limited to 'pkg_resources/tests/test_resources.py')
| -rw-r--r-- | pkg_resources/tests/test_resources.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index ba12d857..7176cc70 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -671,3 +671,37 @@ class TestNamespaces: os.path.join(self._real_tmpdir, "site-pkgs2", "pkg1", "pkg2"), ] assert pkg1.pkg2.__path__ == expected + + def test_path_order(self): + """ + Test that if multiple versions of the same namespace package subpackage + are on different sys.path entries, that only the one earliest on + sys.path is imported, and that the namespace package's __path__ is in + the correct order. + + Regression test for https://bitbucket.org/pypa/setuptools/issues/207 + """ + + site_pkgs = ["site-pkgs", "site-pkgs2", "site-pkgs3"] + + ns_str = "__import__('pkg_resources').declare_namespace(__name__)\n" + vers_str = "__version__ = %r" + + for idx, site in enumerate(site_pkgs): + if idx > 0: + sys.path.append(os.path.join(self._tmpdir, site)) + os.makedirs(os.path.join(self._tmpdir, site, "nspkg", "subpkg")) + with open(os.path.join(self._tmpdir, site, "nspkg", + "__init__.py"), "w") as f: + f.write(ns_str) + + with open(os.path.join(self._tmpdir, site, "nspkg", "subpkg", + "__init__.py"), "w") as f: + f.write(vers_str % (idx + 1)) + + import nspkg.subpkg + import nspkg + assert nspkg.__path__ == [os.path.join(self._real_tmpdir, site, + "nspkg") + for site in site_pkgs] + assert nspkg.subpkg.__version__ == 1 |
