Ejemplo n.º 1
0
def test_debian_egg_name_workaround(script):
    """
    We can uninstall packages installed with the pyversion removed from the
    egg-info metadata directory name.

    Refs:
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=618367
    https://bugs.launchpad.net/ubuntu/+source/distribute/+bug/725178
    https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux

    """
    result = script.pip('install', 'INITools==0.2', expect_error=True)

    egg_info = os.path.join(
        script.site_packages, "INITools-0.2-py%s.egg-info" % pyversion)

    # Debian only removes pyversion for global installs, not inside a venv
    # so even if this test runs on a Debian/Ubuntu system with broken setuptools,
    # since our test runs inside a venv we'll still have the normal .egg-info
    assert egg_info in result.files_created, "Couldn't find %s" % egg_info

    # The Debian no-pyversion version of the .egg-info
    mangled = os.path.join(script.site_packages, "INITools-0.2.egg-info")
    assert mangled not in result.files_created, "Found unexpected %s" % mangled

    # Simulate a Debian install by copying the .egg-info to their name for it
    full_egg_info = os.path.join(script.base_path, egg_info)
    assert os.path.isdir(full_egg_info)
    full_mangled = os.path.join(script.base_path, mangled)
    os.renames(full_egg_info, full_mangled)
    assert os.path.isdir(full_mangled)

    # Try the uninstall and verify that everything is removed.
    result2 = script.pip("uninstall", "INITools", "-y")
    assert_all_changes(result, result2, [script.venv/'build', 'cache'])
Ejemplo n.º 2
0
    def test_uninstall_from_usersite_with_dist_in_global_site(self, script, virtualenv):
        """
        Test uninstall from usersite (with same dist in global site)
        """
        # 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 piptestpackage is not 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 has sys.path precedence over the virtualenv site

        virtualenv.system_site_packages = True
        script.environ["PYTHONPATH"] = script.base_path / script.user_site
        _patch_dist_in_site_packages(script)

        result1 = script.pip_install_local('pip-test-package==0.1')
        result2 = script.pip_install_local('--user', 'pip-test-package==0.1.1')
        result3 = script.pip('uninstall', '-vy', 'pip-test-package')

        # uninstall console is mentioning user scripts, but not global scripts
        assert script.user_bin_path in result3.stdout
        assert script.bin_path not in result3.stdout

        # uninstall worked
        assert_all_changes(result2, result3, [script.venv/'build', 'cache'])

        # site still has 0.2 (can't look in result1; have to check)
        egg_info_folder = script.base_path / script.site_packages / 'pip_test_package-0.1-py%s.egg-info' % pyversion
        assert isdir(egg_info_folder)
Ejemplo n.º 3
0
def test_uninstall_rollback(script, data):
    """
    Test uninstall-rollback (using test package with a setup.py
    crafted to fail on install).

    """
    result = script.pip(
        'install', '-f', data.find_links, '--no-index', 'broken==0.1'
    )
    assert script.site_packages / 'broken.py' in result.files_created, list(
        result.files_created.keys()
    )
    result2 = script.pip(
        'install', '-f', data.find_links, '--no-index', 'broken===0.2broken',
        expect_error=True,
    )
    assert result2.returncode == 1, str(result2)
    assert script.run(
        'python', '-c', "import broken; print(broken.VERSION)"
    ).stdout == '0.1\n'
    assert_all_changes(
        result.files_after,
        result2,
        [script.venv / 'build'],
    )
Ejemplo n.º 4
0
def test_upgrade_from_reqs_file():
    """
    Upgrade from a requirements file.

    """
    env = reset_env()
    write_file(
        "test-req.txt",
        textwrap.dedent(
            """\
        PyLogo<0.4
        # and something else to test out:
        INITools==0.3
        """
        ),
    )
    install_result = run_pip("install", "-r", env.scratch_path / "test-req.txt")
    write_file(
        "test-req.txt",
        textwrap.dedent(
            """\
        PyLogo
        # and something else to test out:
        INITools
        """
        ),
    )
    run_pip("install", "--upgrade", "-r", env.scratch_path / "test-req.txt")
    uninstall_result = run_pip("uninstall", "-r", env.scratch_path / "test-req.txt", "-y")
    assert_all_changes(install_result, uninstall_result, [env.venv / "build", "cache", env.scratch / "test-req.txt"])
Ejemplo n.º 5
0
def test_uninstall_from_reqs_file():
    """
    Test uninstall from a requirements file.

    """
    env = reset_env()
    write_file('test-req.txt', textwrap.dedent("""\
        -e %s#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
    result = run_pip('install', '-r', 'test-req.txt')
    write_file('test-req.txt', textwrap.dedent("""\
        # -f, -i, and --extra-index-url should all be ignored by uninstall
        -f http://www.example.com
        -i http://www.example.com
        --extra-index-url http://www.example.com

        -e %s#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
    result2 = run_pip('uninstall', '-r', 'test-req.txt', '-y')
    assert_all_changes(
        result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
Ejemplo n.º 6
0
def test_uninstall_overlapping_package(script, data):
    """
    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 = data.packages.join("parent-0.1.tar.gz")
    child_pkg = data.packages.join("child-0.1.tar.gz")

    result1 = script.pip('install', parent_pkg, expect_error=False)
    assert join(script.site_packages, 'parent') in result1.files_created, sorted(result1.files_created.keys())
    result2 = script.pip('install', child_pkg, expect_error=False)
    assert join(script.site_packages, 'child') in result2.files_created, sorted(result2.files_created.keys())
    assert normpath(join(script.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
    script.run('python', '-c', "import parent.plugins.child_plugin, child")
    result3 = script.pip('uninstall', '-y', 'child', expect_error=False)
    assert join(script.site_packages, 'child') in result3.files_deleted, sorted(result3.files_created.keys())
    assert normpath(join(script.site_packages, 'parent/plugins/child_plugin.py')) in result3.files_deleted, sorted(result3.files_deleted.keys())
    assert join(script.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, [])
Ejemplo n.º 7
0
    def test_uninstall_editable_from_usersite(self, script, virtualenv, data):
        """
        Test uninstall editable local user install
        """
        virtualenv.system_site_packages = True
        script.user_site_path.makedirs()

        # install
        to_install = data.packages.join("FSPkg")
        result1 = script.pip(
            'install', '--user', '-e', to_install, expect_error=False,
        )
        egg_link = script.user_site / 'FSPkg.egg-link'
        assert egg_link in result1.files_created, str(result1.stdout)

        # uninstall
        result2 = script.pip('uninstall', '-y', 'FSPkg')
        assert not isfile(script.base_path / egg_link)

        assert_all_changes(
            result1,
            result2,
            [
                script.venv / 'build',
                'cache',
                script.user_site / 'easy-install.pth',
            ]
        )
Ejemplo n.º 8
0
 def test_uninstall_from_usersite(self, script):
     """
     Test uninstall from usersite
     """
     result1 = script.pip('install', '--user', 'INITools==0.3')
     result2 = script.pip('uninstall', '-y', 'INITools')
     assert_all_changes(result1, result2, [script.venv / 'build', 'cache'])
Ejemplo n.º 9
0
def test_uninstall_from_reqs_file(script, tmpdir):
    """
    Test uninstall from a requirements file.

    """
    script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
        -e %s#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk', tmpdir.join("cache"))))
    result = script.pip('install', '-r', 'test-req.txt')
    script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
        # -f, -i, and --extra-index-url should all be ignored by uninstall
        -f http://www.example.com
        -i http://www.example.com
        --extra-index-url http://www.example.com

        -e %s#egg=initools-dev
        # and something else to test out:
        PyLogo<0.4
        """ % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk', tmpdir.join("cache"))))
    result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y')
    assert_all_changes(
        result, result2, [script.venv/'build', script.venv/'src', script.scratch/'test-req.txt',
        script.site_packages/'easy-install.pth'])
Ejemplo n.º 10
0
    def test_uninstall_from_usersite_with_dist_in_global_site(
            self, virtualenv, script):
        """
        Test uninstall from usersite (with same dist in global site)
        """
        _patch_dist_in_site_packages(virtualenv)

        script.pip_install_local('pip-test-package==0.1', '--no-binary=:all:')

        result2 = script.pip_install_local(
            '--user', 'pip-test-package==0.1.1', '--no-binary=:all:')
        result3 = script.pip('uninstall', '-vy', 'pip-test-package')

        # uninstall console is mentioning user scripts, but not global scripts
        assert normcase(script.user_bin_path) in result3.stdout, str(result3)
        assert normcase(script.bin_path) not in result3.stdout, str(result3)

        # uninstall worked
        assert_all_changes(result2, result3, [script.venv / 'build', 'cache'])

        # site still has 0.2 (can't look in result1; have to check)
        egg_info_folder = (
            script.base_path / script.site_packages /
            'pip_test_package-0.1-py%s.egg-info' % pyversion
        )
        assert isdir(egg_info_folder)
Ejemplo n.º 11
0
def _test_uninstall_editable_with_source_outside_venv(tmpdir):
    env = reset_env()
    result = env.run('git', 'clone', local_repo('git+git://github.com/pypa/virtualenv'), tmpdir)
    result2 = run_pip('install', '-e', tmpdir)
    assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), list(result2.files_created.keys())
    result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
    assert_all_changes(result, result3, [env.venv/'build'])
Ejemplo n.º 12
0
def test_upgrade_from_reqs_file(script):
    """
    Upgrade from a requirements file.

    """
    script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
        PyLogo<0.4
        # and something else to test out:
        INITools==0.3
        """))
    install_result = script.pip(
        'install', '-r', script.scratch_path / 'test-req.txt'
    )
    script.scratch_path.join("test-req.txt").write(textwrap.dedent("""\
        PyLogo
        # and something else to test out:
        INITools
        """))
    script.pip(
        'install', '--upgrade', '-r', script.scratch_path / 'test-req.txt'
    )
    uninstall_result = script.pip(
        'uninstall', '-r', script.scratch_path / 'test-req.txt', '-y'
    )
    assert_all_changes(
        install_result,
        uninstall_result,
        [script.venv / 'build', 'cache', script.scratch / 'test-req.txt'],
    )
Ejemplo n.º 13
0
 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'])
Ejemplo n.º 14
0
 def test_uninstall_from_usersite(self, script, virtualenv):
     """
     Test uninstall from usersite
     """
     virtualenv.system_site_packages = True
     result1 = script.pip('install', '--user', 'INITools==0.3')
     result2 = script.pip('uninstall', '-y', 'INITools')
     assert_all_changes(result1, result2, [script.venv/'build', 'cache'])
Ejemplo n.º 15
0
def test_uninstall_editable_from_svn(script, tmpdir):
    """
    Test uninstalling an editable installation from svn.
    """
    result = script.pip('install', '-e', '%s#egg=initools-dev' %
                     local_checkout('svn+http://svn.colorstudy.com/INITools/trunk', tmpdir.join("cache")))
    result.assert_installed('INITools')
    result2 = script.pip('uninstall', '-y', 'initools')
    assert (script.venv/'src'/'initools' in result2.files_after), 'oh noes, pip deleted my sources!'
    assert_all_changes(result, result2, [script.venv/'src', script.venv/'build', script.site_packages/'easy-install.pth'])
Ejemplo n.º 16
0
def test_uninstall_easy_installed_console_scripts(script):
    """
    Test uninstalling package with console_scripts that is easy_installed.
    """
    args = ['easy_install']
    args.append('discover')
    result = script.run(*args, **{"expect_stderr": True})
    assert script.bin/'discover'+script.exe in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('uninstall', 'discover', '-y')
    assert_all_changes(result, result2, [script.venv/'build', 'cache', script.site_packages/'easy-install.pth'])
Ejemplo n.º 17
0
def test_uninstall_wheel(script, data):
    """
    Test uninstalling a wheel
    """
    package = data.packages.join("simple.dist-0.1-py2.py3-none-any.whl")
    result = script.pip('install', package, '--no-index')
    dist_info_folder = script.site_packages / 'simple.dist-0.1.dist-info'
    assert dist_info_folder in result.files_created
    result2 = script.pip('uninstall', 'simple.dist', '-y')
    assert_all_changes(result, result2, [])
Ejemplo n.º 18
0
def test_uninstall_easy_install_after_import(script):
    """
    Uninstall an easy_installed package after it's been imported

    """
    result = script.run('easy_install', 'INITools==0.2', expect_stderr=True)
    #the import forces the generation of __pycache__ if the version of python supports it
    script.run('python', '-c', "import initools")
    result2 = script.pip('uninstall', 'INITools', '-y')
    assert_all_changes(result, result2, [script.venv/'build', 'cache', script.site_packages/'easy-install.pth'])
Ejemplo n.º 19
0
def test_uninstall_console_scripts(script):
    """
    Test uninstalling a package with more files (console_script entry points, extra directories).
    """
    args = ['install']
    args.append('discover')
    result = script.pip(*args, **{"expect_error": True})
    assert script.bin/'discover'+script.exe in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('uninstall', 'discover', '-y', expect_error=True)
    assert_all_changes(result, result2, [script.venv/'build', 'cache'])
Ejemplo n.º 20
0
def test_upgrade_force_reinstall_newest(script):
    """
    Force reinstallation of a package even if it is already at its newest
    version if --force-reinstall is supplied.
    """
    result = script.pip('install', 'INITools')
    assert script.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('install', '--upgrade', '--force-reinstall', 'INITools')
    assert result2.files_updated, 'upgrade to INITools 0.3 failed'
    result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [script.venv/'build', 'cache'])
Ejemplo n.º 21
0
def test_uninstall_before_upgrade(script):
    """
    Automatic uninstall-before-upgrade.

    """
    result = script.pip('install', 'INITools==0.2', expect_error=True)
    assert script.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('install', 'INITools==0.3', expect_error=True)
    assert result2.files_created, 'upgrade to INITools 0.3 failed'
    result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [script.venv/'build', 'cache'])
Ejemplo n.º 22
0
def test_uninstall_with_scripts(script):
    """
    Uninstall an easy_installed package with scripts.

    """
    result = script.run('easy_install', 'PyLogo', expect_stderr=True)
    easy_install_pth = script.site_packages/ 'easy-install.pth'
    pylogo = sys.platform == 'win32' and 'pylogo' or 'PyLogo'
    assert(pylogo in result.files_updated[easy_install_pth].bytes)
    result2 = script.pip('uninstall', 'pylogo', '-y')
    assert_all_changes(result, result2, [script.venv/'build', 'cache', easy_install_pth])
Ejemplo n.º 23
0
def test_uninstall_before_upgrade_from_url(script):
    """
    Automatic uninstall-before-upgrade from URL.

    """
    result = script.pip('install', 'INITools==0.2', expect_error=True)
    assert script.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('install', 'http://pypi.python.org/packages/source/I/INITools/INITools-0.3.tar.gz', expect_error=True)
    assert result2.files_created, 'upgrade to INITools 0.3 failed'
    result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [script.venv/'build', 'cache'])
Ejemplo n.º 24
0
def test_simple_uninstall(script):
    """
    Test simple install and uninstall.

    """
    result = script.pip('install', 'INITools==0.2')
    assert join(script.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
    script.run('python', '-c', "import initools")
    result2 = script.pip('uninstall', 'INITools', '-y')
    assert_all_changes(result, result2, [script.venv/'build', 'cache'])
Ejemplo n.º 25
0
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'])
Ejemplo n.º 26
0
def test_uninstall_before_upgrade():
    """
    Automatic uninstall-before-upgrade.

    """
    env = reset_env()
    result = run_pip("install", "INITools==0.2", expect_error=True)
    assert env.site_packages / "initools" in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip("install", "INITools==0.3", expect_error=True)
    assert result2.files_created, "upgrade to INITools 0.3 failed"
    result3 = run_pip("uninstall", "initools", "-y", expect_error=True)
    assert_all_changes(result, result3, [env.venv / "build", "cache"])
Ejemplo n.º 27
0
def test_upgrade_to_same_version_from_url(script):
    """
    When installing from a URL the same version that is already installed, no
    need to uninstall and reinstall if --upgrade is not specified.

    """
    result = script.pip('install', 'INITools==0.3', expect_error=True)
    assert script.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
    result2 = script.pip('install', 'http://pypi.python.org/packages/source/I/INITools/INITools-0.3.tar.gz', expect_error=True)
    assert not result2.files_updated, 'INITools 0.3 reinstalled same version'
    result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
    assert_all_changes(result, result3, [script.venv/'build', 'cache'])
Ejemplo n.º 28
0
def test_uninstall_easy_installed_console_scripts():
    """
    Test uninstalling package with console_scripts that is easy_installed.

    """
    env = reset_env()
    args = ['easy_install']
    args.append('discover')
    result = env.run(*args, **{"expect_stderr": True})
    assert env.bin/'discover'+env.exe in result.files_created, sorted(result.files_created.keys())
    result2 = run_pip('uninstall', 'discover', '-y')
    assert_all_changes(result, result2, [env.venv/'build', 'cache'])
Ejemplo n.º 29
0
def test_uninstall_editable_from_svn():
    """
    Test uninstalling an editable installation from svn.

    """
    env = reset_env()
    result = run_pip('install', '-e', '%s#egg=initools-dev' %
                     local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
    result.assert_installed('INITools')
    result2 = run_pip('uninstall', '-y', 'initools')
    assert (env.venv/'src'/'initools' in result2.files_after), 'oh noes, pip deleted my sources!'
    assert_all_changes(result, result2, [env.venv/'src', env.venv/'build'])
Ejemplo n.º 30
0
def test_uninstall_rollback():
    """
    Test uninstall-rollback (using test package with a setup.py
    crafted to fail on install).

    """
    env = reset_env()
    result = run_pip('install', '-f', find_links, '--no-index', 'broken==0.1')
    assert env.site_packages / 'broken.py' in result.files_created, list(result.files_created.keys())
    result2 = run_pip('install', '-f', find_links, '--no-index', 'broken==0.2broken', expect_error=True)
    assert result2.returncode == 1, str(result2)
    assert env.run('python', '-c', "import broken; print(broken.VERSION)").stdout == '0.1\n'
    assert_all_changes(result.files_after, result2, [env.venv/'build', 'pip-log.txt'])
Ejemplo n.º 31
0
def test_uninstall_editable_from_svn(script, tmpdir):
    """
    Test uninstalling an editable installation from svn.
    """
    result = script.pip(
        'install', '-e',
        '%s#egg=initools' % (
            local_checkout('svn+http://svn.colorstudy.com/INITools', tmpdir)
        ),
    )
    result.assert_installed('INITools')
    result2 = script.pip('uninstall', '-y', 'initools')
    assert (script.venv / 'src' / 'initools' in result2.files_after)
    assert_all_changes(
        result,
        result2,
        [
            script.venv / 'src',
            script.venv / 'build',
            script.site_packages / 'easy-install.pth'
        ],
    )
Ejemplo n.º 32
0
def test_uninstall_from_reqs_file(script: PipTestEnvironment,
                                  tmpdir: Path) -> None:
    """
    Test uninstall from a requirements file.

    """
    local_svn_url = local_checkout(
        "svn+http://svn.colorstudy.com/INITools",
        tmpdir,
    )
    script.scratch_path.joinpath("test-req.txt").write_text(
        textwrap.dedent("""
            -e {url}#egg=initools
            # and something else to test out:
            PyLogo<0.4
        """).format(url=local_svn_url))
    result = script.pip("install", "-r", "test-req.txt")
    script.scratch_path.joinpath("test-req.txt").write_text(
        textwrap.dedent("""
            # -f, -i, and --extra-index-url should all be ignored by uninstall
            -f http://www.example.com
            -i http://www.example.com
            --extra-index-url http://www.example.com

            -e {url}#egg=initools
            # and something else to test out:
            PyLogo<0.4
        """).format(url=local_svn_url))
    result2 = script.pip("uninstall", "-r", "test-req.txt", "-y")
    assert_all_changes(
        result,
        result2,
        [
            script.venv / "build",
            script.venv / "src",
            script.scratch / "test-req.txt",
            script.site_packages / "easy-install.pth",
        ],
    )
Ejemplo n.º 33
0
def test_debian_egg_name_workaround(script):
    """
    We can uninstall packages installed with the pyversion removed from the
    egg-info metadata directory name.

    Refs:
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=618367
    https://bugs.launchpad.net/ubuntu/+source/distribute/+bug/725178
    https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux

    """
    result = script.pip('install', 'INITools==0.2')

    egg_info = os.path.join(
        script.site_packages,
        "INITools-0.2-py{pyversion}.egg-info".format(**globals()))

    # Debian only removes pyversion for global installs, not inside a venv
    # so even if this test runs on a Debian/Ubuntu system with broken
    # setuptools, since our test runs inside a venv we'll still have the normal
    # .egg-info
    assert egg_info in result.files_created, \
        "Couldn't find {egg_info}".format(**locals())

    # The Debian no-pyversion version of the .egg-info
    mangled = os.path.join(script.site_packages, "INITools-0.2.egg-info")
    assert mangled not in result.files_created, \
        "Found unexpected {mangled}".format(**locals())

    # Simulate a Debian install by copying the .egg-info to their name for it
    full_egg_info = os.path.join(script.base_path, egg_info)
    assert os.path.isdir(full_egg_info)
    full_mangled = os.path.join(script.base_path, mangled)
    os.renames(full_egg_info, full_mangled)
    assert os.path.isdir(full_mangled)

    # Try the uninstall and verify that everything is removed.
    result2 = script.pip("uninstall", "INITools", "-y")
    assert_all_changes(result, result2, [script.venv / 'build', 'cache'])
Ejemplo n.º 34
0
def _test_uninstall_editable_with_source_outside_venv(
    script,
    tmpdir,
    temp_pkg_dir,
):
    result = script.run(
        'git',
        'clone',
        local_repo('git+git://github.com/pypa/pip-test-package', tmpdir),
        temp_pkg_dir,
        expect_stderr=True,
    )
    result2 = script.pip('install', '-e', temp_pkg_dir)
    assert join(script.site_packages,
                'pip-test-package.egg-link') in result2.files_created, list(
                    result2.files_created.keys())
    result3 = script.pip('uninstall', '-y', 'pip-test-package')
    assert_all_changes(
        result,
        result3,
        [script.venv / 'build', script.site_packages / 'easy-install.pth'],
    )
Ejemplo n.º 35
0
def test_uninstall_from_reqs_file(script, tmpdir):
    """
    Test uninstall from a requirements file.

    """
    local_svn_url = local_checkout(
        'svn+http://svn.colorstudy.com/INITools', tmpdir,
    )
    script.scratch_path.joinpath("test-req.txt").write_text(
        textwrap.dedent("""
            -e {url}#egg=initools
            # and something else to test out:
            PyLogo<0.4
        """).format(url=local_svn_url)
    )
    result = script.pip('install', '-r', 'test-req.txt')
    script.scratch_path.joinpath("test-req.txt").write_text(
        textwrap.dedent("""
            # -f, -i, and --extra-index-url should all be ignored by uninstall
            -f http://www.example.com
            -i http://www.example.com
            --extra-index-url http://www.example.com

            -e {url}#egg=initools
            # and something else to test out:
            PyLogo<0.4
        """).format(url=local_svn_url)
    )
    result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y')
    assert_all_changes(
        result,
        result2,
        [
            script.venv / 'build',
            script.venv / 'src',
            script.scratch / 'test-req.txt',
            script.site_packages / 'easy-install.pth',
        ],
    )
Ejemplo n.º 36
0
def test_uninstall_overlapping_package(script, data):
    """
    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 = data.packages.joinpath("parent-0.1.tar.gz")
    child_pkg = data.packages.joinpath("child-0.1.tar.gz")

    result1 = script.pip('install', parent_pkg)
    assert join(script.site_packages, 'parent') in result1.files_created, (
        sorted(result1.files_created.keys())
    )
    result2 = script.pip('install', child_pkg)
    assert join(script.site_packages, 'child') in result2.files_created, (
        sorted(result2.files_created.keys())
    )
    assert normpath(
        join(script.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
    script.run('python', '-c', "import parent.plugins.child_plugin, child")
    result3 = script.pip('uninstall', '-y', 'child')
    assert join(script.site_packages, 'child') in result3.files_deleted, (
        sorted(result3.files_created.keys())
    )
    assert normpath(
        join(script.site_packages, 'parent/plugins/child_plugin.py')
    ) in result3.files_deleted, sorted(result3.files_deleted.keys())
    assert join(script.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, [])
Ejemplo n.º 37
0
    def test_uninstall_from_usersite_with_dist_in_global_site(
            self, script, virtualenv):
        """
        Test uninstall from usersite (with same dist in global site)
        """
        # 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 piptestpackage is not 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 has sys.path precedence
        #    over the virtualenv site

        virtualenv.system_site_packages = True
        script.environ["PYTHONPATH"] = script.base_path / script.user_site
        _patch_dist_in_site_packages(script)

        script.pip_install_local('pip-test-package==0.1', '--no-binary=:all:')

        result2 = script.pip_install_local('--user', 'pip-test-package==0.1.1',
                                           '--no-binary=:all:')
        result3 = script.pip('uninstall', '-vy', 'pip-test-package')

        # uninstall console is mentioning user scripts, but not global scripts
        assert script.user_bin_path in result3.stdout
        assert script.bin_path not in result3.stdout

        # uninstall worked
        assert_all_changes(result2, result3, [script.venv / 'build', 'cache'])

        # site still has 0.2 (can't look in result1; have to check)
        egg_info_folder = (script.base_path / script.site_packages /
                           'pip_test_package-0.1-py%s.egg-info' % pyversion)
        assert isdir(egg_info_folder)
Ejemplo n.º 38
0
    def test_uninstall_editable_from_usersite(self):
        """
        Test uninstall editable local user install
        """
        env = reset_env(system_site_packages=True)

        #install
        to_install = abspath(join(tests_data, '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'])
Ejemplo n.º 39
0
def test_uninstall_editable_from_svn(script: PipTestEnvironment,
                                     tmpdir: Path) -> None:
    """
    Test uninstalling an editable installation from svn.
    """
    result = script.pip(
        "install",
        "-e",
        "{checkout}#egg=initools".format(checkout=local_checkout(
            "svn+http://svn.colorstudy.com/INITools", tmpdir)),
    )
    result.assert_installed("INITools")
    result2 = script.pip("uninstall", "-y", "initools")
    assert script.venv / "src" / "initools" in result2.files_after
    assert_all_changes(
        result,
        result2,
        [
            script.venv / "src",
            script.venv / "build",
            script.site_packages / "easy-install.pth",
        ],
    )
Ejemplo n.º 40
0
def test_uninstall_console_scripts(script: PipTestEnvironment) -> None:
    """
    Test uninstalling a package with more files (console_script entry points,
    extra directories).
    """
    pkg_path = create_test_package_with_setup(
        script,
        name="discover",
        version="0.1",
        entry_points={"console_scripts": ["discover = discover:main"]},
    )
    result = script.pip("install", pkg_path)
    result.did_create(script.bin / "discover" + script.exe)
    result2 = script.pip("uninstall", "discover", "-y")
    assert_all_changes(
        result,
        result2,
        [
            script.venv / "build",
            "cache",
            Path("scratch") / "discover" / "discover.egg-info",
        ],
    )
Ejemplo n.º 41
0
def test_uninstall_easy_install_after_import(
        script: PipTestEnvironment) -> None:
    """
    Uninstall an easy_installed package after it's been imported

    """
    # setuptools 52 removed easy_install.
    script.pip("install", "setuptools==51.3.3", use_module=True)

    result = script.easy_install("INITools==0.2", expect_stderr=True)
    # the import forces the generation of __pycache__ if the version of python
    # supports it
    script.run("python", "-c", "import initools")
    result2 = script.pip("uninstall", "INITools", "-y")
    assert_all_changes(
        result,
        result2,
        [
            script.venv / "build",
            "cache",
            script.site_packages / "easy-install.pth",
        ],
    )
Ejemplo n.º 42
0
def test_uninstall_rollback(script, data):
    """
    Test uninstall-rollback (using test package with a setup.py
    crafted to fail on install).

    """
    result = script.pip(
        'install', '-f', data.find_links, '--no-index', 'broken==0.1'
    )
    result.did_create(script.site_packages / 'broken.py')
    result2 = script.pip(
        'install', '-f', data.find_links, '--no-index', 'broken===0.2broken',
        expect_error=True,
    )
    assert result2.returncode == 1, str(result2)
    assert script.run(
        'python', '-c', "import broken; print(broken.VERSION)"
    ).stdout == '0.1\n'
    assert_all_changes(
        result.files_after,
        result2,
        [script.venv / 'build'],
    )
Ejemplo n.º 43
0
def check_force_reinstall(script, specifier, expected):
    """
    Args:
      specifier: the requirement specifier to force-reinstall.
      expected: the expected version after force-reinstalling.
    """
    result = script.pip_install_local('simplewheel==1.0')
    check_installed_version(script, 'simplewheel', '1.0')

    # Remove an installed file to test whether --force-reinstall fixes it.
    to_fix = script.site_packages_path.joinpath("simplewheel", "__init__.py")
    to_fix.unlink()

    result2 = script.pip_install_local('--force-reinstall', specifier)
    check_installed_version(script, 'simplewheel', expected)

    # site_packages_path is absolute, but files_created mapping uses
    # relative paths as key.
    fixed_key = os.path.relpath(to_fix, script.base_path)
    result2.did_create(fixed_key, message='force-reinstall failed')

    result3 = script.pip('uninstall', 'simplewheel', '-y')
    assert_all_changes(result, result3, [script.venv / 'build', 'cache'])
Ejemplo n.º 44
0
def check_force_reinstall(script: PipTestEnvironment, specifier: str,
                          expected: str) -> None:
    """
    Args:
      specifier: the requirement specifier to force-reinstall.
      expected: the expected version after force-reinstalling.
    """
    result = script.pip_install_local("simplewheel==1.0")
    check_installed_version(script, "simplewheel", "1.0")

    # Remove an installed file to test whether --force-reinstall fixes it.
    to_fix = script.site_packages_path.joinpath("simplewheel", "__init__.py")
    to_fix.unlink()

    result2 = script.pip_install_local("--force-reinstall", specifier)
    check_installed_version(script, "simplewheel", expected)

    # site_packages_path is absolute, but files_created mapping uses
    # relative paths as key.
    fixed_key = os.path.relpath(to_fix, script.base_path)
    result2.did_create(fixed_key, message="force-reinstall failed")

    result3 = script.pip("uninstall", "simplewheel", "-y")
    assert_all_changes(result, result3, [script.venv / "build", "cache"])
Ejemplo n.º 45
0
    def test_uninstall_from_usersite_with_dist_in_global_site(
            self, virtualenv, script):
        """
        Test uninstall from usersite (with same dist in global site)
        """
        _patch_dist_in_site_packages(virtualenv)

        script.pip_install_local('pip-test-package==0.1', '--no-binary=:all:')

        result2 = script.pip_install_local('--user', 'pip-test-package==0.1.1',
                                           '--no-binary=:all:')
        result3 = script.pip('uninstall', '-vy', 'pip-test-package')

        # uninstall console is mentioning user scripts, but not global scripts
        assert normcase(script.user_bin_path) in result3.stdout, str(result3)
        assert normcase(script.bin_path) not in result3.stdout, str(result3)

        # uninstall worked
        assert_all_changes(result2, result3, [script.venv / 'build', 'cache'])

        # site still has 0.2 (can't look in result1; have to check)
        egg_info_folder = (script.base_path / script.site_packages /
                           'pip_test_package-0.1-py%s.egg-info' % pyversion)
        assert isdir(egg_info_folder)