1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_req_uninstall.py

50 lines
1.4 KiB
Python
Raw Normal View History

2015-03-19 01:37:24 +01:00
import os
import shutil
import sys
import tempfile
import pytest
from mock import Mock
from pip.locations import running_under_virtualenv
from pip.req.req_uninstall import UninstallPathSet
2015-03-19 17:35:53 +01:00
2015-03-19 01:37:24 +01:00
class TestUninstallPathSet(object):
def setup(self):
if running_under_virtualenv():
# Construct tempdir in sys.prefix, otherwise UninstallPathSet
# will reject paths.
self.tempdir = tempfile.mkdtemp(prefix=sys.prefix)
else:
self.tempdir = tempfile.mkdtemp()
def teardown(self):
shutil.rmtree(self.tempdir, ignore_errors=True)
def test_add(self):
file_extant = os.path.join(self.tempdir, 'foo')
file_nonexistant = os.path.join(self.tempdir, 'nonexistant')
2015-03-19 17:35:53 +01:00
with open(file_extant, 'w'):
pass
2015-03-19 01:37:24 +01:00
ups = UninstallPathSet(dist=Mock())
assert ups.paths == set()
ups.add(file_extant)
assert ups.paths == set([file_extant])
ups.add(file_nonexistant)
assert ups.paths == set([file_extant])
@pytest.mark.skipif("sys.platform == 'win32'")
def test_add_symlink(self):
f = os.path.join(self.tempdir, 'foo')
2015-03-19 17:35:53 +01:00
with open(f, 'w'):
pass
2015-03-19 01:37:24 +01:00
l = os.path.join(self.tempdir, 'foo_link')
os.symlink(f, l)
ups = UninstallPathSet(dist=Mock())
ups.add(l)
assert ups.paths == set([l])