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:
commit
0c599b68e8
|
@ -1463,10 +1463,11 @@ class UninstallPathSet(object):
|
||||||
def remove(self, auto_confirm=False):
|
def remove(self, auto_confirm=False):
|
||||||
"""Remove paths in ``self.paths`` with confirmation (unless
|
"""Remove paths in ``self.paths`` with confirmation (unless
|
||||||
``auto_confirm`` is True)."""
|
``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():
|
if not self._can_uninstall():
|
||||||
return
|
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.notify('Uninstalling %s:' % self.dist.project_name)
|
||||||
logger.indent += 2
|
logger.indent += 2
|
||||||
paths = sorted(self.compact(self.paths))
|
paths = sorted(self.compact(self.paths))
|
||||||
|
|
|
@ -91,7 +91,7 @@ def test_freeze_git_clone():
|
||||||
expected = textwrap.dedent("""\
|
expected = textwrap.dedent("""\
|
||||||
Script result: ...pip freeze
|
Script result: ...pip freeze
|
||||||
-- stdout: --------------------
|
-- stdout: --------------------
|
||||||
-e %s@...#egg=pip_test_package-...
|
...-e %s@...#egg=pip_test_package-...
|
||||||
...""" % local_checkout('git+http://github.com/pypa/pip-test-package.git'))
|
...""" % local_checkout('git+http://github.com/pypa/pip-test-package.git'))
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ def test_freeze_git_clone():
|
||||||
expected = textwrap.dedent("""\
|
expected = textwrap.dedent("""\
|
||||||
Script result: pip freeze -f %(repo)s#egg=pip_test_package
|
Script result: pip freeze -f %(repo)s#egg=pip_test_package
|
||||||
-- stdout: --------------------
|
-- stdout: --------------------
|
||||||
-f %(repo)s#egg=pip_test_package
|
-f %(repo)s#egg=pip_test_package...
|
||||||
-e %(repo)s@...#egg=pip_test_package-dev
|
-e %(repo)s@...#egg=pip_test_package-dev
|
||||||
...""" % {'repo': local_checkout('git+http://github.com/pypa/pip-test-package.git')})
|
...""" % {'repo': local_checkout('git+http://github.com/pypa/pip-test-package.git')})
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
@ -124,7 +124,7 @@ def test_freeze_mercurial_clone():
|
||||||
expected = textwrap.dedent("""\
|
expected = textwrap.dedent("""\
|
||||||
Script result: ...pip freeze
|
Script result: ...pip freeze
|
||||||
-- stdout: --------------------
|
-- stdout: --------------------
|
||||||
-e %s@...#egg=django_authority-...
|
...-e %s@...#egg=django_authority-...
|
||||||
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-authority'))
|
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-authority'))
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ def test_freeze_mercurial_clone():
|
||||||
Script result: ...pip freeze -f %(repo)s#egg=django_authority
|
Script result: ...pip freeze -f %(repo)s#egg=django_authority
|
||||||
-- stdout: --------------------
|
-- stdout: --------------------
|
||||||
-f %(repo)s#egg=django_authority
|
-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')})
|
...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-authority')})
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ def test_freeze_bazaar_clone():
|
||||||
expected = textwrap.dedent("""\
|
expected = textwrap.dedent("""\
|
||||||
Script result: ...pip freeze
|
Script result: ...pip freeze
|
||||||
-- stdout: --------------------
|
-- 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'))
|
...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ def test_freeze_bazaar_clone():
|
||||||
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
|
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
|
||||||
-- stdout: --------------------
|
-- stdout: --------------------
|
||||||
-f %(repo)s/#egg=django-wikiapp
|
-f %(repo)s/#egg=django-wikiapp
|
||||||
-e %(repo)s@...#egg=django_wikiapp-...
|
...-e %(repo)s@...#egg=django_wikiapp-...
|
||||||
...""" % {'repo':
|
...""" % {'repo':
|
||||||
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
|
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
|
||||||
_check_output(result, expected)
|
_check_output(result, expected)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import textwrap
|
||||||
import sys
|
import sys
|
||||||
from os.path import join, abspath, normpath
|
from os.path import join, abspath, normpath
|
||||||
from tempfile import mkdtemp
|
from tempfile import mkdtemp
|
||||||
from mock import Mock
|
from mock import Mock, patch
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
from tests.test_pip import here, reset_env, run_pip, assert_all_changes, write_file, pyversion
|
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
|
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'])
|
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.req import UninstallPathSet
|
||||||
from pip.exceptions import InstallationError
|
from pip.exceptions import InstallationError
|
||||||
mock_dist = Mock(project_name='pkg')
|
from pkg_resources import get_distribution
|
||||||
uninstall_set = UninstallPathSet(mock_dist)
|
test_dist = get_distribution('pip')
|
||||||
assert_raises(InstallationError, uninstall_set.remove)
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue