mirror of https://github.com/pypa/pip
raise InstallationError when UninstallPathSet has no paths
This commit is contained in:
parent
4c96de642d
commit
0e3c03f958
|
@ -1457,6 +1457,8 @@ class UninstallPathSet(object):
|
|||
def remove(self, auto_confirm=False):
|
||||
"""Remove paths in ``self.paths`` with confirmation (unless
|
||||
``auto_confirm`` is True)."""
|
||||
if not self.paths:
|
||||
raise InstallationError("Can't uninstall '%s'. No files were found to uninstall." % self.dist.project_name)
|
||||
if not self._can_uninstall():
|
||||
return
|
||||
logger.notify('Uninstalling %s:' % self.dist.project_name)
|
||||
|
|
|
@ -2,6 +2,7 @@ import textwrap
|
|||
import sys
|
||||
from os.path import join, abspath
|
||||
from tempfile import mkdtemp
|
||||
from mock import Mock
|
||||
from tests.test_pip import here, reset_env, run_pip, assert_all_changes, write_file, pyversion
|
||||
from tests.local_repos import local_repo, local_checkout
|
||||
|
||||
|
@ -155,3 +156,19 @@ def test_uninstall_as_egg():
|
|||
result2 = run_pip('uninstall', 'FSPkg', '-y', expect_error=True)
|
||||
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
|
||||
|
||||
|
||||
def test_uninstallpathset_no_paths():
|
||||
"""
|
||||
Test UninstallPathSet raises installation error when there are no paths (uses mocking)
|
||||
|
||||
"""
|
||||
from pip.req import UninstallPathSet
|
||||
from pip.exceptions import InstallationError
|
||||
mock_dist = Mock(project_name='pkg')
|
||||
uninstall_set = UninstallPathSet(mock_dist)
|
||||
try:
|
||||
uninstall_set.remove()
|
||||
assert False, "Uninstalling with no paths should have thrown InstallationError"
|
||||
except InstallationError:
|
||||
e = sys.exc_info()[1]
|
||||
assert str(e) == "Can't uninstall 'pkg'. No files were found to uninstall.", str(e)
|
||||
|
|
Loading…
Reference in New Issue