1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/functional/test_install_cleanup.py

139 lines
4.4 KiB
Python
Raw Normal View History

import os
from os.path import exists
2017-05-16 12:16:30 +02:00
import pytest
2018-07-30 06:10:59 +02:00
from pip._internal.cli.status_codes import PREVIOUS_BUILD_DIR_ERROR
from pip._internal.utils.marker_files import write_delete_marker_file
from tests.lib import need_mercurial
2017-05-16 12:16:30 +02:00
from tests.lib.local_repos import local_checkout
2010-04-18 14:10:04 +02:00
def test_cleanup_after_install(script, data):
2010-04-18 14:10:04 +02:00
"""
2013-03-27 06:26:52 +01:00
Test clean up after installing a package.
2010-04-18 14:10:04 +02:00
"""
script.pip(
'install', '--no-index', '--find-links=%s' % data.find_links, 'simple'
)
build = script.venv_path / "build"
src = script.venv_path / "src"
2010-04-18 14:10:04 +02:00
assert not exists(build), "build/ dir still exists: %s" % build
assert not exists(src), "unexpected src/ dir exists: %s" % src
script.assert_no_temp()
2010-04-18 14:10:04 +02:00
2015-01-15 00:53:15 +01:00
@pytest.mark.network
def test_no_clean_option_blocks_cleaning_after_install(script, data):
2013-03-27 06:26:52 +01:00
"""
2013-05-25 02:11:15 +02:00
Test --no-clean option blocks cleaning after install
2013-03-27 06:26:52 +01:00
"""
build = script.base_path / 'pip-build'
script.pip(
'install', '--no-clean', '--no-index', '--build', build,
2017-05-19 20:06:20 +02:00
'--find-links=%s' % data.find_links, 'simple', expect_temp=True,
)
assert exists(build)
2013-05-25 02:11:15 +02:00
2015-01-15 00:53:15 +01:00
@pytest.mark.network
@need_mercurial
def test_cleanup_after_install_editable_from_hg(script, tmpdir):
2010-04-18 14:10:04 +02:00
"""
Test clean up after cloning from Mercurial.
2010-04-18 14:10:04 +02:00
"""
script.pip(
'install',
'-e',
'%s#egg=ScriptTest' %
local_checkout('hg+https://bitbucket.org/ianb/scripttest', tmpdir),
)
build = script.venv_path / 'build'
src = script.venv_path / 'src'
2010-04-18 14:10:04 +02:00
assert not exists(build), "build/ dir still exists: %s" % build
assert exists(src), "expected src/ dir doesn't exist: %s" % src
script.assert_no_temp()
2010-04-18 14:10:04 +02:00
def test_cleanup_after_install_from_local_directory(script, data):
2010-04-18 14:10:04 +02:00
"""
Test clean up after installing from a local directory.
"""
to_install = data.packages.joinpath("FSPkg")
script.pip('install', to_install, expect_error=False)
build = script.venv_path / 'build'
src = script.venv_path / 'src'
2010-04-18 14:10:04 +02:00
assert not exists(build), "unexpected build/ dir exists: %s" % build
assert not exists(src), "unexpected src/ dir exist: %s" % src
script.assert_no_temp()
2010-04-18 14:10:04 +02:00
2019-09-06 10:29:34 +02:00
def test_cleanup_req_satisfied_no_name(script, data):
"""
2012-07-29 06:09:07 +02:00
Test cleanup when req is already satisfied, and req has no 'name'
"""
2014-03-26 23:24:19 +01:00
# this test confirms Issue #420 is fixed
# reqs with no 'name' that were already satisfied were leaving behind tmp
# build dirs
2014-03-26 23:24:19 +01:00
# 2 examples of reqs that would do this
2012-07-29 06:09:07 +02:00
# 1) https://bitbucket.org/ianb/initools/get/tip.zip
# 2) parent-0.1.tar.gz
dist = data.packages.joinpath("parent-0.1.tar.gz")
script.pip('install', dist)
script.pip('install', dist)
build = script.venv_path / 'build'
2012-07-29 06:09:07 +02:00
assert not exists(build), "unexpected build/ dir exists: %s" % build
script.assert_no_temp()
def test_cleanup_after_install_exception(script, data):
2013-03-27 06:26:52 +01:00
"""
Test clean up after a 'setup.py install' exception.
"""
2014-03-26 23:24:19 +01:00
# broken==0.2broken fails during install; see packages readme file
result = script.pip(
'install', '-f', data.find_links, '--no-index', 'broken==0.2broken',
expect_error=True,
)
build = script.venv_path / 'build'
2013-03-27 06:26:52 +01:00
assert not exists(build), "build/ dir still exists: %s" % result.stdout
script.assert_no_temp()
2013-03-27 06:26:52 +01:00
def test_cleanup_after_egg_info_exception(script, data):
2013-03-27 06:26:52 +01:00
"""
Test clean up after a 'setup.py egg_info' exception.
"""
2014-03-26 23:24:19 +01:00
# brokenegginfo fails during egg_info; see packages readme file
result = script.pip(
'install', '-f', data.find_links, '--no-index', 'brokenegginfo==0.1',
expect_error=True,
)
build = script.venv_path / 'build'
2013-03-27 06:26:52 +01:00
assert not exists(build), "build/ dir still exists: %s" % result.stdout
script.assert_no_temp()
2013-07-24 11:02:08 +02:00
2015-01-15 00:53:15 +01:00
@pytest.mark.network
def test_cleanup_prevented_upon_build_dir_exception(script, data):
2013-07-24 11:02:08 +02:00
"""
Test no cleanup occurs after a PreviousBuildDirError
"""
build = script.venv_path / 'build'
build_simple = build / 'simple'
os.makedirs(build_simple)
write_delete_marker_file(build_simple)
build_simple.joinpath("setup.py").write_text("#")
result = script.pip(
'install', '-f', data.find_links, '--no-index', 'simple',
'--build', build,
2017-05-19 20:11:06 +02:00
expect_error=True, expect_temp=True,
)
assert result.returncode == PREVIOUS_BUILD_DIR_ERROR, str(result)
assert "pip can't proceed" in result.stderr, str(result)
assert exists(build_simple), str(result)