1""" 2tests specific to uninstalling --user installs 3""" 4from os.path import isdir, isfile, normcase 5 6import pytest 7 8from tests.functional.test_install_user import _patch_dist_in_site_packages 9from tests.lib import pyversion # noqa: F401 10from tests.lib import assert_all_changes 11 12 13@pytest.mark.incompatible_with_test_venv 14class Tests_UninstallUserSite: 15 16 @pytest.mark.network 17 def test_uninstall_from_usersite(self, script): 18 """ 19 Test uninstall from usersite 20 """ 21 result1 = script.pip('install', '--user', 'INITools==0.3') 22 result2 = script.pip('uninstall', '-y', 'INITools') 23 assert_all_changes(result1, result2, [script.venv / 'build', 'cache']) 24 25 def test_uninstall_from_usersite_with_dist_in_global_site( 26 self, virtualenv, script): 27 """ 28 Test uninstall from usersite (with same dist in global site) 29 """ 30 _patch_dist_in_site_packages(virtualenv) 31 32 script.pip_install_local('pip-test-package==0.1', '--no-binary=:all:') 33 34 result2 = script.pip_install_local( 35 '--user', 'pip-test-package==0.1.1', '--no-binary=:all:') 36 result3 = script.pip('uninstall', '-vy', 'pip-test-package') 37 38 # uninstall console is mentioning user scripts, but not global scripts 39 assert normcase(script.user_bin_path) in result3.stdout, str(result3) 40 assert normcase(script.bin_path) not in result3.stdout, str(result3) 41 42 # uninstall worked 43 assert_all_changes(result2, result3, [script.venv / 'build', 'cache']) 44 45 # site still has 0.2 (can't look in result1; have to check) 46 # keep checking for egg-info because no-binary implies setup.py install 47 egg_info_folder = ( 48 script.base_path / script.site_packages / 49 'pip_test_package-0.1-py{pyversion}.egg-info'.format(**globals()) 50 ) 51 assert isdir(egg_info_folder) 52 53 def test_uninstall_editable_from_usersite(self, script, data): 54 """ 55 Test uninstall editable local user install 56 """ 57 assert script.user_site_path.exists() 58 59 # install 60 to_install = data.packages.joinpath("FSPkg") 61 result1 = script.pip( 62 'install', '--user', '-e', to_install 63 ) 64 egg_link = script.user_site / 'FSPkg.egg-link' 65 result1.did_create(egg_link) 66 67 # uninstall 68 result2 = script.pip('uninstall', '-y', 'FSPkg') 69 assert not isfile(script.base_path / egg_link) 70 71 assert_all_changes( 72 result1, 73 result2, 74 [ 75 script.venv / 'build', 76 'cache', 77 script.user_site / 'easy-install.pth', 78 ] 79 ) 80