diff options
Diffstat (limited to 'tests/test_user_site.py')
-rw-r--r-- | tests/test_user_site.py | 95 |
1 files changed, 76 insertions, 19 deletions
diff --git a/tests/test_user_site.py b/tests/test_user_site.py index 4e997692e..2d1eec924 100644 --- a/tests/test_user_site.py +++ b/tests/test_user_site.py @@ -6,7 +6,15 @@ import sys from os.path import abspath, join, curdir, isdir, isfile from nose import SkipTest from tests.local_repos import local_checkout -from tests.test_pip import here, reset_env, run_pip, pyversion +from tests.test_pip import here, reset_env, run_pip, pyversion, assert_all_changes + + +patch_dist_in_site_packages = """ + def dist_in_site_packages(dist): + return False + import pip + pip.util.dist_in_site_packages=dist_in_site_packages +""" def test_install_curdir_usersite_fails_in_old_python(): @@ -27,6 +35,10 @@ class Tests_UserSite: # --user only works on 2.6 or higher if sys.version_info < (2, 6): raise SkipTest() + # --user option is broken in pypy + if hasattr(sys, "pypy_version_info"): + raise SkipTest() + def test_reset_env_system_site_packages_usersite(self): """ @@ -58,9 +70,6 @@ class Tests_UserSite: """ Test installing current directory ('.') into usersite after installing distribute """ - # FIXME distutils --user option seems to be broken in pypy - if hasattr(sys, "pypy_version_info"): - raise SkipTest() env = reset_env(use_distribute=True, system_site_packages=True) result = run_pip('install', '--user', '-e', '%s#egg=initools-dev' % @@ -72,9 +81,6 @@ class Tests_UserSite: """ Test installing current directory ('.') into usersite """ - # FIXME distutils --user option seems to be broken in pypy - if hasattr(sys, "pypy_version_info"): - raise SkipTest() env = reset_env(use_distribute=True, system_site_packages=True) run_from = abspath(join(here, 'packages', 'FSPkg')) result = run_pip('install', '--user', curdir, cwd=run_from, expect_error=False) @@ -111,15 +117,21 @@ class Tests_UserSite: assert not isfile(initools_v3_file), initools_v3_file - def test_install_user_conflict_in_site(self): + def test_install_user_conflict_in_globalsite(self): """ - Test user install with conflict in site ignores site and installs to usersite + Test user install with conflict in global site ignores site and installs to usersite """ - #the test framework only supports testing using virtualenvs - #this test will use a --system_site_packages virtualenv to achieve the conflict scenario. + # the test framework only supports testing using virtualenvs + # the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv-site, user-site, global-site + # this test will use 2 modifications to simulate the user-site/global-site relationship + # 1) a monkey patch which will make it appear INITools==0.2 is not in in the virtualenv site + # if we don't patch this, pip will return an installation error: "Will not install to the usersite because it will lack sys.path precedence..." + # 2) adding usersite to PYTHONPATH, so usersite as sys.path precedence over the virtualenv site + + env = reset_env(system_site_packages=True, sitecustomize=patch_dist_in_site_packages) + env.environ["PYTHONPATH"] = env.root_path / env.user_site - env = reset_env(system_site_packages=True) result1 = run_pip('install', 'INITools==0.2') result2 = run_pip('install', '--user', 'INITools==0.1') @@ -141,14 +153,14 @@ class Tests_UserSite: Test user install with conflict in globalsite and usersite ignores global site and updates usersite. """ - #the test framework only supports testing using virtualenvs - #this test will use a --system_site_packages virtualenv to achieve the conflict scenario. - - env = reset_env(system_site_packages=True) + # the test framework only supports testing using virtualenvs. + # the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv-site, user-site, global-site. + # this test will use 2 modifications to simulate the user-site/global-site relationship + # 1) a monkey patch which will make it appear INITools==0.2 is not in in the virtualenv site + # if we don't patch this, pip will return an installation error: "Will not install to the usersite because it will lack sys.path precedence..." + # 2) adding usersite to PYTHONPATH, so usersite as sys.path precedence over the virtualenv site - # the sys.path ordering for virtualenvs with --system-site-packages is this: virtualenv site, usersite, global site - # given this ordering you *can't* use it to simulate the scenario for this test. - # this test will add the usersite to PYTHONPATH to simulate the desired ordering + env = reset_env(system_site_packages=True, sitecustomize=patch_dist_in_site_packages) env.environ["PYTHONPATH"] = env.root_path / env.user_site result1 = run_pip('install', 'INITools==0.2') @@ -166,3 +178,48 @@ class Tests_UserSite: initools_folder = env.root_path / env.site_packages / 'initools' assert isdir(egg_info_folder) assert isdir(initools_folder) + + + def test_install_user_in_global_virtualenv_with_conflict_fails(self): + """ + Test user install in --system-site-packages virtualenv with conflict in site fails. + """ + env = reset_env(system_site_packages=True) + result1 = run_pip('install', 'INITools==0.2') + result2 = run_pip('install', '--user', 'INITools==0.1', expect_error=True) + resultp = env.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').location)") + dist_location = resultp.stdout.strip() + assert result2.stdout.startswith("Will not install to the user site because it will lack sys.path precedence to %s in %s" + %('INITools', dist_location)), result2.stdout + + + def test_uninstall_from_usersite(self): + """ + Test uninstall from usersite + """ + env = reset_env(system_site_packages=True) + result1 = run_pip('install', '--user', 'INITools==0.3') + result2 = run_pip('uninstall', '-y', 'INITools') + assert_all_changes(result1, result2, [env.venv/'build', 'cache']) + + + def test_uninstall_editable_from_usersite(self): + """ + Test uninstall editable local user install + """ + env = reset_env(use_distribute=True, system_site_packages=True) + + #install + to_install = abspath(join(here, 'packages', 'FSPkg')) + result1 = run_pip('install', '--user', '-e', to_install, expect_error=False) + egg_link = env.user_site/'FSPkg.egg-link' + assert egg_link in result1.files_created, str(result1.stdout) + + #uninstall + result2 = run_pip('uninstall', '-y', 'FSPkg') + assert not isfile(env.root_path / egg_link) + + assert_all_changes(result1, result2, + [env.venv/'build', 'cache', env.user_site/'easy-install.pth']) + + |