Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests for easy-install.pth uninstall #6517

Merged
merged 2 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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