summaryrefslogtreecommitdiff
path: root/tests/test_uninstall.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_uninstall.py')
-rw-r--r--tests/test_uninstall.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/test_uninstall.py b/tests/test_uninstall.py
index 21b111710..28339a615 100644
--- a/tests/test_uninstall.py
+++ b/tests/test_uninstall.py
@@ -1,7 +1,9 @@
import textwrap
import sys
-from os.path import join, abspath
+from os.path import join, abspath, normpath
from tempfile import mkdtemp
+from mock import Mock
+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
@@ -16,6 +18,8 @@ def test_simple_uninstall():
env = reset_env()
result = run_pip('install', 'INITools==0.2')
assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys())
+ #the import forces the generation of __pycache__ if the version of python supports it
+ env.run('python', '-c', "import initools")
result2 = run_pip('uninstall', 'INITools', '-y')
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
@@ -34,6 +38,19 @@ def test_uninstall_with_scripts():
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
+def test_uninstall_easy_install_after_import():
+ """
+ Uninstall an easy_installed package after it's been imported
+
+ """
+ env = reset_env()
+ result = env.run('easy_install', 'INITools==0.2', expect_stderr=True)
+ #the import forces the generation of __pycache__ if the version of python supports it
+ env.run('python', '-c', "import initools")
+ result2 = run_pip('uninstall', 'INITools', '-y')
+ assert_all_changes(result, result2, [env.venv/'build', 'cache'])
+
+
def test_uninstall_namespace_package():
"""
Uninstall a distribution with a namespace package without clobbering
@@ -48,6 +65,33 @@ def test_uninstall_namespace_package():
assert join(env.site_packages, 'pd', 'find') in result2.files_deleted, sorted(result2.files_deleted.keys())
+def test_uninstall_overlapping_package():
+ """
+ Uninstalling a distribution that adds modules to a pre-existing package
+ should only remove those added modules, not the rest of the existing
+ package.
+
+ See: GitHub issue #355 (pip uninstall removes things it didn't install)
+ """
+ parent_pkg = abspath(join(here, 'packages', 'parent-0.1.tar.gz'))
+ child_pkg = abspath(join(here, 'packages', 'child-0.1.tar.gz'))
+ env = reset_env()
+ result1 = run_pip('install', parent_pkg, expect_error=False)
+ assert join(env.site_packages, 'parent') in result1.files_created, sorted(result1.files_created.keys())
+ result2 = run_pip('install', child_pkg, expect_error=False)
+ assert join(env.site_packages, 'child') in result2.files_created, sorted(result2.files_created.keys())
+ assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result2.files_created, sorted(result2.files_created.keys())
+ #the import forces the generation of __pycache__ if the version of python supports it
+ env.run('python', '-c', "import parent.plugins.child_plugin, child")
+ result3 = run_pip('uninstall', '-y', 'child', expect_error=False)
+ assert join(env.site_packages, 'child') in result3.files_deleted, sorted(result3.files_created.keys())
+ assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result3.files_deleted, sorted(result3.files_deleted.keys())
+ assert join(env.site_packages, 'parent') not in result3.files_deleted, sorted(result3.files_deleted.keys())
+ # Additional check: uninstalling 'child' should return things to the
+ # previous state, without unintended side effects.
+ assert_all_changes(result2, result3, [])
+
+
def test_uninstall_console_scripts():
"""
Test uninstalling a package with more files (console_script entry points, extra directories).
@@ -155,3 +199,14 @@ 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)
+ assert_raises(InstallationError, uninstall_set.remove)