From 0e3c03f9581bccb37854e8c262967ae5307d0319 Mon Sep 17 00:00:00 2001 From: Marcus Smith Date: Mon, 25 Jun 2012 22:35:27 -0700 Subject: [PATCH] raise InstallationError when UninstallPathSet has no paths --- pip/req.py | 2 ++ tests/test_uninstall.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/pip/req.py b/pip/req.py index efea080f1..07a65344e 100644 --- a/pip/req.py +++ b/pip/req.py @@ -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) diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py index 21b111710..aeb023c64 100644 --- a/tests/test_uninstall.py +++ b/tests/test_uninstall.py @@ -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)