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

Merge pull request #657 from qwcode/issue_656

Issue 656   just log warning when no uninstall paths, don't raise error
This commit is contained in:
Marcus Smith 2012-09-04 15:36:51 -07:00
commit 0c599b68e8
3 changed files with 37 additions and 14 deletions

View file

@ -1463,10 +1463,11 @@ 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
if not self.paths:
logger.notify("Can't uninstall '%s'. No files were found to uninstall." % self.dist.project_name)
return
logger.notify('Uninstalling %s:' % self.dist.project_name)
logger.indent += 2
paths = sorted(self.compact(self.paths))

View file

@ -91,7 +91,7 @@ def test_freeze_git_clone():
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=pip_test_package-...
...-e %s@...#egg=pip_test_package-...
...""" % local_checkout('git+http://github.com/pypa/pip-test-package.git'))
_check_output(result, expected)
@ -101,7 +101,7 @@ def test_freeze_git_clone():
expected = textwrap.dedent("""\
Script result: pip freeze -f %(repo)s#egg=pip_test_package
-- stdout: --------------------
-f %(repo)s#egg=pip_test_package
-f %(repo)s#egg=pip_test_package...
-e %(repo)s@...#egg=pip_test_package-dev
...""" % {'repo': local_checkout('git+http://github.com/pypa/pip-test-package.git')})
_check_output(result, expected)
@ -124,7 +124,7 @@ def test_freeze_mercurial_clone():
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_authority-...
...-e %s@...#egg=django_authority-...
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-authority'))
_check_output(result, expected)
@ -135,7 +135,7 @@ def test_freeze_mercurial_clone():
Script result: ...pip freeze -f %(repo)s#egg=django_authority
-- stdout: --------------------
-f %(repo)s#egg=django_authority
-e %(repo)s@...#egg=django_authority-dev
...-e %(repo)s@...#egg=django_authority-dev
...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-authority')})
_check_output(result, expected)
@ -156,7 +156,7 @@ def test_freeze_bazaar_clone():
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_wikiapp-...
...-e %s@...#egg=django_wikiapp-...
...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
_check_output(result, expected)
@ -168,7 +168,7 @@ def test_freeze_bazaar_clone():
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
-- stdout: --------------------
-f %(repo)s/#egg=django-wikiapp
-e %(repo)s@...#egg=django_wikiapp-...
...-e %(repo)s@...#egg=django_wikiapp-...
...""" % {'repo':
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
_check_output(result, expected)

View file

@ -2,7 +2,7 @@ import textwrap
import sys
from os.path import join, abspath, normpath
from tempfile import mkdtemp
from mock import Mock
from mock import Mock, patch
from nose.tools import assert_raises
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
@ -200,13 +200,35 @@ def test_uninstall_as_egg():
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
def test_uninstallpathset_no_paths():
@patch('pip.req.logger')
def test_uninstallpathset_no_paths(mock_logger):
"""
Test UninstallPathSet raises installation error when there are no paths (uses mocking)
Test UninstallPathSet logs notification when there are no paths to uninstall
"""
from pip.req import UninstallPathSet
from pip.exceptions import InstallationError
mock_dist = Mock(project_name='pkg')
uninstall_set = UninstallPathSet(mock_dist)
assert_raises(InstallationError, uninstall_set.remove)
from pkg_resources import get_distribution
test_dist = get_distribution('pip')
uninstall_set = UninstallPathSet(test_dist)
uninstall_set.remove() #with no files added to set
mock_logger.notify.assert_any_call("Can't uninstall 'pip'. No files were found to uninstall.")
@patch('pip.req.logger')
def test_uninstallpathset_non_local(mock_logger):
"""
Test UninstallPathSet logs notification and returns (with no exception) when dist is non-local
"""
from pip.req import UninstallPathSet
from pip.exceptions import InstallationError
from pkg_resources import get_distribution
test_dist = get_distribution('pip')
test_dist.location = '/NON_LOCAL'
uninstall_set = UninstallPathSet(test_dist)
uninstall_set.remove() #with no files added to set; which is the case when trying to remove non-local dists
mock_logger.notify.assert_any_call("Not uninstalling pip at /NON_LOCAL, outside environment %s" % sys.prefix)