Example #1
0
 def test_compact_shorter_path(self, monkeypatch):
     monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                         lambda p: True)
     monkeypatch.setattr('os.path.exists', lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(
         os.path.abspath(os.path.join(os.path.sep, 'path')))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, 'longer'))
     assert compact(ups.paths) == set([short_path])
Example #2
0
 def test_compact_shorter_path(self, monkeypatch):
     monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                         lambda p: True)
     monkeypatch.setattr('os.path.exists', lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(os.path.abspath(
         os.path.join(os.path.sep, 'path')))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, 'longer'))
     assert compact(ups.paths) == {short_path}
Example #3
0
    def test_add_symlink(self, tmpdir, monkeypatch):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            mock_is_local)
        f = os.path.join(tmpdir, 'foo')
        with open(f, 'w'):
            pass
        foo_link = os.path.join(tmpdir, 'foo_link')
        os.symlink(f, foo_link)

        ups = UninstallPathSet(dist=Mock())
        ups.add(foo_link)
        assert ups.paths == {foo_link}
Example #4
0
    def test_add_symlink(self, tmpdir, monkeypatch):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            mock_is_local)
        f = os.path.join(tmpdir, 'foo')
        with open(f, 'w'):
            pass
        l = os.path.join(tmpdir, 'foo_link')
        os.symlink(f, l)

        ups = UninstallPathSet(dist=Mock())
        ups.add(l)
        assert ups.paths == set([l])
Example #5
0
 def test_compact_shorter_path(self,
                               monkeypatch: pytest.MonkeyPatch) -> None:
     monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local",
                         mock_is_local)
     monkeypatch.setattr("os.path.exists", lambda p: True)
     # This deals with nt/posix path differences
     short_path = os.path.normcase(
         os.path.abspath(os.path.join(os.path.sep, "path")))
     ups = UninstallPathSet(dist=Mock())
     ups.add(short_path)
     ups.add(os.path.join(short_path, "longer"))
     assert compact(ups._paths) == {short_path}
Example #6
0
    def test_add_symlink(self, tmpdir: Path,
                         monkeypatch: pytest.MonkeyPatch) -> None:
        monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local",
                            mock_is_local)
        f = os.path.join(tmpdir, "foo")
        with open(f, "w"):
            pass
        foo_link = os.path.join(tmpdir, "foo_link")
        os.symlink(f, foo_link)

        ups = UninstallPathSet(dist=Mock())
        ups.add(foo_link)
        assert ups._paths == {foo_link}
Example #7
0
    def test_add(self, tmpdir, monkeypatch):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            mock_is_local)
        # Fix case for windows tests
        file_extant = os.path.normcase(os.path.join(tmpdir, 'foo'))
        file_nonexistent = os.path.normcase(
            os.path.join(tmpdir, 'nonexistent'))
        with open(file_extant, 'w'):
            pass

        ups = UninstallPathSet(dist=Mock())
        assert ups.paths == set()
        ups.add(file_extant)
        assert ups.paths == {file_extant}

        ups.add(file_nonexistent)
        assert ups.paths == {file_extant}
Example #8
0
    def test_add(self, tmpdir, monkeypatch):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            mock_is_local)
        # Fix case for windows tests
        file_extant = os.path.normcase(os.path.join(tmpdir, 'foo'))
        file_nonexistent = os.path.normcase(os.path.join(
            tmpdir, 'nonexistent'))
        with open(file_extant, 'w'):
            pass

        ups = UninstallPathSet(dist=Mock())
        assert ups.paths == set()
        ups.add(file_extant)
        assert ups.paths == set([file_extant])

        ups.add(file_nonexistent)
        assert ups.paths == set([file_extant])
Example #9
0
    def test_add(self, tmpdir: Path, monkeypatch: pytest.MonkeyPatch) -> None:
        monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local",
                            mock_is_local)
        # Fix case for windows tests
        file_extant = os.path.normcase(os.path.join(tmpdir, "foo"))
        file_nonexistent = os.path.normcase(os.path.join(
            tmpdir, "nonexistent"))
        with open(file_extant, "w"):
            pass

        ups = UninstallPathSet(dist=Mock())
        assert ups._paths == set()
        ups.add(file_extant)
        assert ups._paths == {file_extant}

        ups.add(file_nonexistent)
        assert ups._paths == {file_extant}
Example #10
0
    def test_detect_symlink_dirs(self, monkeypatch, tmpdir):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            lambda p: True)

        # construct 2 paths:
        #  tmpdir/dir/file
        #  tmpdir/dirlink/file (where dirlink is a link to dir)
        d = tmpdir.join('dir')
        d.mkdir()
        dlink = tmpdir.join('dirlink')
        os.symlink(d, dlink)
        d.join('file').touch()
        path1 = str(d.join('file'))
        path2 = str(dlink.join('file'))

        ups = UninstallPathSet(dist=Mock())
        ups.add(path1)
        ups.add(path2)
        assert ups.paths == {path1}
Example #11
0
    def test_detect_symlink_dirs(self, monkeypatch, tmpdir):
        monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
                            lambda p: True)

        # construct 2 paths:
        #  tmpdir/dir/file
        #  tmpdir/dirlink/file (where dirlink is a link to dir)
        d = tmpdir.join('dir')
        d.mkdir()
        dlink = tmpdir.join('dirlink')
        os.symlink(d, dlink)
        d.join('file').touch()
        path1 = str(d.join('file'))
        path2 = str(dlink.join('file'))

        ups = UninstallPathSet(dist=Mock())
        ups.add(path1)
        ups.add(path2)
        assert ups.paths == set([path1])
Example #12
0
    def test_detect_symlink_dirs(self, monkeypatch: pytest.MonkeyPatch,
                                 tmpdir: Path) -> None:
        monkeypatch.setattr(pip._internal.req.req_uninstall, "is_local",
                            mock_is_local)

        # construct 2 paths:
        #  tmpdir/dir/file
        #  tmpdir/dirlink/file (where dirlink is a link to dir)
        d = tmpdir.joinpath("dir")
        d.mkdir()
        dlink = tmpdir.joinpath("dirlink")
        os.symlink(d, dlink)
        d.joinpath("file").touch()
        path1 = str(d.joinpath("file"))
        path2 = str(dlink.joinpath("file"))

        ups = UninstallPathSet(dist=Mock())
        ups.add(path1)
        ups.add(path2)
        assert ups._paths == {path1}