2010-07-01 07:07:34 +02:00
|
|
|
import os
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2014-01-28 15:17:51 +01:00
|
|
|
from os.path import exists
|
2013-08-23 13:12:37 +02:00
|
|
|
|
2013-05-27 19:46:31 +02:00
|
|
|
from tests.lib.local_repos import local_checkout
|
|
|
|
from tests.lib.path import Path
|
2013-08-22 22:17:01 +02:00
|
|
|
from pip.locations import write_delete_marker_file
|
|
|
|
from pip.status_codes import PREVIOUS_BUILD_DIR_ERROR
|
2010-04-18 14:10:04 +02:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2013-08-23 13:12:37 +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
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
script.pip(
|
|
|
|
'install', '--no-index', '--find-links=%s' % data.find_links, 'simple'
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
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
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2010-04-18 14:10:04 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
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
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '--no-clean', '--no-index',
|
|
|
|
'--find-links=%s' % data.find_links, 'simple'
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
build = script.venv_path/'build'/'simple'
|
2013-03-27 06:26:52 +01:00
|
|
|
assert exists(build), "build/simple should still exist %s" % str(result)
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-05-25 02:11:15 +02:00
|
|
|
|
2013-08-22 12:14:09 +02:00
|
|
|
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-06-03 04:25:26 +02:00
|
|
|
|
2010-04-18 14:10:04 +02:00
|
|
|
"""
|
2014-01-28 15:17:51 +01:00
|
|
|
script.pip(
|
|
|
|
'install',
|
|
|
|
'-e',
|
|
|
|
'%s#egg=ScriptTest' %
|
|
|
|
local_checkout(
|
|
|
|
'hg+https://bitbucket.org/ianb/scripttest',
|
|
|
|
tmpdir.join("cache"),
|
|
|
|
),
|
|
|
|
expect_error=True,
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
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
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2010-04-18 14:10:04 +02:00
|
|
|
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2013-08-23 13:12:37 +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.
|
|
|
|
"""
|
2013-08-23 13:12:37 +02:00
|
|
|
to_install = data.packages.join("FSPkg")
|
2013-08-21 11:16:07 +02:00
|
|
|
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
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2010-04-18 14:10:04 +02:00
|
|
|
|
2011-05-04 09:44:02 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_no_install_and_download_should_not_leave_build_dir(script):
|
2010-07-01 07:07:34 +02:00
|
|
|
"""
|
|
|
|
It should remove build/ dir if it was pip that created
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
script.scratch_path.join("downloaded_packages").mkdir()
|
|
|
|
assert not os.path.exists(script.venv_path/'/build')
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '--no-install', 'INITools==0.2', '-d', 'downloaded_packages'
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
Path('scratch')/'downloaded_packages/build'
|
|
|
|
not in result.files_created
|
|
|
|
), 'pip should not leave build/ dir'
|
|
|
|
assert not os.path.exists(script.venv_path/'/build'), (
|
|
|
|
"build/ dir should be deleted"
|
|
|
|
)
|
2010-07-01 07:07:34 +02:00
|
|
|
|
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
def test_cleanup_req_satisifed_no_name(script, data):
|
2012-07-13 01:00:24 +02:00
|
|
|
"""
|
2012-07-29 06:09:07 +02:00
|
|
|
Test cleanup when req is already satisfied, and req has no 'name'
|
2012-07-13 01:00:24 +02:00
|
|
|
"""
|
2012-07-29 06:09:07 +02:00
|
|
|
#this test confirms Issue #420 is fixed
|
2014-01-28 15:17:51 +01:00
|
|
|
#reqs with no 'name' that were already satisfied were leaving behind tmp
|
|
|
|
# build dirs
|
2012-07-29 06:09:07 +02:00
|
|
|
#2 examples of reqs that would do this
|
|
|
|
# 1) https://bitbucket.org/ianb/initools/get/tip.zip
|
|
|
|
# 2) parent-0.1.tar.gz
|
2013-08-23 13:12:37 +02:00
|
|
|
dist = data.packages.join("parent-0.1.tar.gz")
|
2014-01-28 15:17:51 +01:00
|
|
|
|
|
|
|
script.pip('install', dist)
|
|
|
|
script.pip('install', dist)
|
|
|
|
|
2013-08-21 11:16:07 +02:00
|
|
|
build = script.venv_path/'build'
|
2012-07-29 06:09:07 +02:00
|
|
|
assert not exists(build), "unexpected build/ dir exists: %s" % build
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2012-07-13 01:00:24 +02:00
|
|
|
|
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
def test_download_should_not_delete_existing_build_dir(script):
|
2010-07-01 07:07:34 +02:00
|
|
|
"""
|
|
|
|
It should not delete build/ if existing before run the command
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
script.venv_path.join("build").mkdir()
|
|
|
|
script.venv_path.join("build", "somefile.txt").write("I am not empty!")
|
|
|
|
script.pip('install', '--no-install', 'INITools==0.2', '-d', '.')
|
|
|
|
with open(script.venv_path/'build'/'somefile.txt') as fp:
|
|
|
|
content = fp.read()
|
2014-01-28 15:17:51 +01:00
|
|
|
assert os.path.exists(script.venv_path/'build'), (
|
|
|
|
"build/ should be left if it exists before pip run"
|
|
|
|
)
|
|
|
|
assert content == 'I am not empty!', (
|
|
|
|
"it should not affect build/ and its content"
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
assert ['somefile.txt'] == os.listdir(script.venv_path/'build')
|
2013-03-27 06:26:52 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
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.
|
|
|
|
"""
|
|
|
|
#broken==0.2broken fails during install; see packages readme file
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-f', data.find_links, '--no-index', 'broken==0.2broken',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
build = script.venv_path/'build'
|
2013-03-27 06:26:52 +01:00
|
|
|
assert not exists(build), "build/ dir still exists: %s" % result.stdout
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2013-03-27 06:26:52 +01:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02: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.
|
|
|
|
"""
|
|
|
|
#brokenegginfo fails during egg_info; see packages readme file
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-f', data.find_links, '--no-index', 'brokenegginfo==0.1',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
2013-08-21 11:16:07 +02:00
|
|
|
build = script.venv_path/'build'
|
2013-03-27 06:26:52 +01:00
|
|
|
assert not exists(build), "build/ dir still exists: %s" % result.stdout
|
2013-08-21 11:16:07 +02:00
|
|
|
script.assert_no_temp()
|
2013-07-24 11:02:08 +02:00
|
|
|
|
2013-08-22 06:40:46 +02:00
|
|
|
|
2013-08-23 13:12:37 +02:00
|
|
|
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
|
|
|
|
"""
|
2013-08-21 11:16:07 +02:00
|
|
|
build = script.venv_path/'build'/'simple'
|
2013-07-24 11:02:08 +02:00
|
|
|
os.makedirs(build)
|
2013-08-22 22:17:01 +02:00
|
|
|
write_delete_marker_file(script.venv_path/'build')
|
2013-08-21 11:16:07 +02:00
|
|
|
build.join("setup.py").write("#")
|
2014-01-28 15:17:51 +01:00
|
|
|
result = script.pip(
|
|
|
|
'install', '-f', data.find_links, '--no-index', 'simple',
|
|
|
|
expect_error=True,
|
|
|
|
)
|
2013-08-22 22:17:01 +02:00
|
|
|
|
|
|
|
assert result.returncode == PREVIOUS_BUILD_DIR_ERROR
|
2013-07-24 11:02:08 +02:00
|
|
|
assert "pip can't proceed" in result.stdout, result.stdout
|
|
|
|
assert exists(build)
|