Skip to content

Test failures in test_resources on Windows #591

Closed

Description

@jaraco

Running the tests on Windows, I see these two failures, apparently related to the case normalization:

_____________________ TestNamespaces.test_two_levels_deep _____________________

self = <pkg_resources.tests.test_resources.TestNamespaces object at 0x000001B5938F1240>
symlinked_tmpdir = local('C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-of-jaraco\\pytest-1\\test_two_levels_deep0-lin
ked')

    def test_two_levels_deep(self, symlinked_tmpdir):
        """
            Test nested namespace packages
            Create namespace packages in the following tree :
                site-packages-1/pkg1/pkg2
                site-packages-2/pkg1/pkg2
            Check both are in the _namespace_packages dict and that their __path__
            is correct
            """
        real_tmpdir = symlinked_tmpdir.realpath()
        tmpdir = symlinked_tmpdir
        sys.path.append(str(tmpdir / 'site-pkgs2'))
        site_dirs = tmpdir / 'site-pkgs', tmpdir / 'site-pkgs2'
        for site in site_dirs:
            pkg1 = site / 'pkg1'
            pkg2 = pkg1 / 'pkg2'
            pkg2.ensure_dir()
            (pkg1 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
            (pkg2 / '__init__.py').write_text(self.ns_str, encoding='utf-8')
        import pkg1
        assert "pkg1" in pkg_resources._namespace_packages
        # attempt to import pkg2 from site-pkgs2
        import pkg1.pkg2
        # check the _namespace_packages dict
        assert "pkg1.pkg2" in pkg_resources._namespace_packages
        assert pkg_resources._namespace_packages["pkg1"] == ["pkg1.pkg2"]
        # check the __path__ attribute contains both paths
        expected = [
            str(real_tmpdir / "site-pkgs" / "pkg1" / "pkg2"),
            str(real_tmpdir / "site-pkgs2" / "pkg1" / "pkg2"),
        ]
>       assert pkg1.pkg2.__path__ == expected
E       assert ['c:\\users\\...\\pkg1\\pkg2'] == ['C:\\Users\\j...\\pkg1\\pkg2']
E         At index 0 diff: 'c:\\users\\jaraco\\appdata\\local\\temp\\pytest-of-jaraco\\pytest-1\\test_two_levels_deep0\\
site-pkgs\\pkg1\\pkg2' != 'C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-of-jaraco\\pytest-1\\test_two_levels_deep0-li
nked\\site-pkgs\\pkg1\\pkg2'
E         Use -v to get the full diff

pkg_resources\tests\test_resources.py:797: AssertionError
_______________________ TestNamespaces.test_path_order ________________________

self = <pkg_resources.tests.test_resources.TestNamespaces object at 0x000001B593919DD8>
symlinked_tmpdir = local('C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-of-jaraco\\pytest-1\\test_path_order0-linked')

    def test_path_order(self, symlinked_tmpdir):
        """
            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://github.com/pypa/setuptools/issues/207
            """

        tmpdir = symlinked_tmpdir
        site_dirs = (
            tmpdir / "site-pkgs",
            tmpdir / "site-pkgs2",
            tmpdir / "site-pkgs3",
        )

        vers_str = "__version__ = %r"

        for number, site in enumerate(site_dirs, 1):
            if number > 1:
                sys.path.append(str(site))
            nspkg = site / 'nspkg'
            subpkg = nspkg / 'subpkg'
            subpkg.ensure_dir()
            (nspkg / '__init__.py').write_text(self.ns_str, encoding='utf-8')
            (subpkg / '__init__.py').write_text(vers_str % number, encoding='utf-8')

        import nspkg.subpkg
        import nspkg
        expected = [
            str(site.realpath() / 'nspkg')
            for site in site_dirs
        ]
>       assert nspkg.__path__ == expected
E       assert ['c:\\users\\...pkgs3\\nspkg'] == ['C:\\Users\\j...pkgs3\\nspkg']
E         At index 0 diff: 'c:\\users\\jaraco\\appdata\\local\\temp\\pytest-of-jaraco\\pytest-1\\test_path_order0\\site-
pkgs\\nspkg' != 'C:\\Users\\jaraco\\AppData\\Local\\Temp\\pytest-of-jaraco\\pytest-1\\test_path_order0-linked\\site-pkgs
\\nspkg'
E         Use -v to get the full diff

pkg_resources\tests\test_resources.py:833: AssertionError

Activity

  1. jaraco commented on May 22, 2016

    @jaraco
    MemberAuthor

    I suspect this is a fairly easy one that just needs the tests updated to match expectation. The big question for me - why does this fail on Windows but not on Unix?

  2. JGoutin commented on Jul 3, 2016

    @JGoutin
    Contributor

    Unlike Unix, Windows don't care about case on paths.

  3. jaraco commented on Jul 22, 2016

    @jaraco
    MemberAuthor

    It seems the test_two_levels_deep started failing with 8a304f3, and test_path_order was introduced in that commit.

    It seems that in that commit, the __path__ of the module started getting re-written with the normalized path rather than the canonical path. I think the behavior should be restored to allow those tests to pass without modification on Windows (but still do case-insensitive comparisons when appropriate).

    @embray Is that something you might be able to spare a few cycles to investigate, especially now that Setuptools has continuous integration tests on Windows?

  4. embray commented on Aug 2, 2016

    @embray
    Contributor

    I can investigate and see if I can reproduce. (Been on vacation off and on the last two weeks but I'll check it out soon as I can.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions