Skip to content

Commit

Permalink
Merge pull request #6517 from blurstudio/uninstall-support-unc
Browse files Browse the repository at this point in the history
Add unit tests for easy-install.pth uninstall
  • Loading branch information
pfmoore authored Aug 7, 2019
2 parents 618f7b6 + 4e339f5 commit d44938c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/6516.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document caveats for UNC paths in uninstall and add .pth unit tests.
5 changes: 5 additions & 0 deletions src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ def add(self, entry):
# backslashes. This is correct for entries that describe absolute
# paths outside of site-packages, but all the others use forward
# slashes.
# os.path.splitdrive is used instead of os.path.isabs because isabs
# treats non-absolute paths with drive letter markings like c:foo\bar
# as absolute paths. It also does not recognize UNC paths if they don't
# have more than "\\sever\share". Valid examples: "\\server\share\" or
# "\\server\share\folder". Python 2.7.8+ support UNC in splitdrive.
if WINDOWS and not os.path.splitdrive(entry)[0]:
entry = entry.replace('\\', '/')
self.entries.add(entry)
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/test_req_uninstall.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys

import pytest
from mock import Mock
Expand All @@ -7,6 +8,7 @@
from pip._internal.req.req_uninstall import (
StashedUninstallPathSet,
UninstallPathSet,
UninstallPthEntries,
compact,
compress_for_output_listing,
compress_for_rename,
Expand Down Expand Up @@ -133,6 +135,38 @@ def test_add(self, tmpdir, monkeypatch):
ups.add(file_nonexistent)
assert ups.paths == {file_extant}

def test_add_pth(self, tmpdir, monkeypatch):
monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
mock_is_local)
# Fix case for windows tests
tmpdir = os.path.normcase(tmpdir)
on_windows = sys.platform == 'win32'
pth_file = os.path.join(tmpdir, 'foo.pth')
relative = '../../example'
if on_windows:
share = '\\\\example\\share\\'
share_com = '\\\\example.com\\share\\'
# Create a .pth file for testing
with open(pth_file, 'w') as f:
f.writelines([tmpdir, '\n',
relative, '\n'])
if on_windows:
f.writelines([share, '\n',
share_com, '\n'])
# Add paths to be removed
pth = UninstallPthEntries(pth_file)
pth.add(tmpdir)
pth.add(relative)
if on_windows:
pth.add(share)
pth.add(share_com)
# Check that the paths were added to entries
if on_windows:
check = set([tmpdir, relative, share, share_com])
else:
check = set([tmpdir, relative])
assert pth.entries == check

@pytest.mark.skipif("sys.platform == 'win32'")
def test_add_symlink(self, tmpdir, monkeypatch):
monkeypatch.setattr(pip._internal.req.req_uninstall, 'is_local',
Expand Down

0 comments on commit d44938c

Please sign in to comment.