提交 1bc31ec0 编写于 作者: D Donald Stufft

Merge pull request #1157 from dstufft/refactor-tests-lib

Refactor tests.lib.* to simplify and remove global state
......@@ -10,7 +10,7 @@ before_install:
- echo -e "[web]\ncacerts = /etc/ssl/certs/ca-certificates.crt" >> ~/.hgrc
- git config --global user.email "python-virtualenv@googlegroups.com"
- git config --global user.name "Pip"
install: pip install pytest git+https://github.com/pypa/virtualenv@develop#egg=virtualenv scripttest mock
install: pip install pytest git+https://github.com/pypa/virtualenv@develop#egg=virtualenv scripttest>=1.3 mock
script: py.test
notifications:
irc: "irc.freenode.org#pip"
......
......@@ -41,7 +41,7 @@ def find_version(*file_paths):
long_description = "\n" + "\n".join([read('PROJECT.txt'),
read('docs', 'quickstart.rst')])
tests_require = ['pytest', 'virtualenv>=1.10', 'scripttest>=1.1.1', 'mock']
tests_require = ['pytest', 'virtualenv>=1.10', 'scripttest>=1.3', 'mock']
setup(name="pip",
version=find_version('pip', '__init__.py'),
......
......@@ -2,7 +2,7 @@ import zipfile
import textwrap
from os.path import abspath, exists, join
from pip.download import path_to_url2
from tests.lib import tests_data, reset_env, run_pip, write_file
from tests.lib import tests_data, reset_env
from tests.lib.path import Path
from tests.lib.local_repos import local_checkout
......@@ -14,16 +14,16 @@ def test_create_bundle():
index (pip itself).
"""
env = reset_env()
script = reset_env()
fspkg = path_to_url2(Path(tests_data)/'packages'/'FSPkg')
run_pip('install', '-e', fspkg)
script.pip('install', '-e', fspkg)
pkg_lines = textwrap.dedent('''\
-e %s
-e %s#egg=initools-dev
pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
write_file('bundle-req.txt', pkg_lines)
script.scratch_path.join("bundle-req.txt").write(pkg_lines)
# Create a bundle in env.scratch_path/ test.pybundle
result = run_pip('bundle', '-r', env.scratch_path/ 'bundle-req.txt', env.scratch_path/ 'test.pybundle')
result = script.pip('bundle', '-r', script.scratch_path/ 'bundle-req.txt', script.scratch_path/ 'test.pybundle')
bundle = result.files_after.get(join('scratch', 'test.pybundle'), None)
assert bundle is not None
......@@ -38,15 +38,15 @@ def test_cleanup_after_create_bundle():
Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/.
"""
env = reset_env()
script = reset_env()
# Install an editable to create a src/ dir.
args = ['install']
args.extend(['-e',
'%s#egg=pip-test-package' %
local_checkout('git+http://github.com/pypa/pip-test-package.git')])
run_pip(*args)
build = env.venv_path/"build"
src = env.venv_path/"src"
script.pip(*args)
build = script.venv_path/"build"
src = script.venv_path/"src"
assert not exists(build), "build/ dir still exists: %s" % build
assert exists(src), "expected src/ dir doesn't exist: %s" % src
......@@ -56,13 +56,13 @@ def test_cleanup_after_create_bundle():
-e %s
-e %s#egg=initools-dev
pip''' % (fspkg, local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')))
write_file('bundle-req.txt', pkg_lines)
run_pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle')
build_bundle = env.scratch_path/"build-bundle"
src_bundle = env.scratch_path/"src-bundle"
script.scratch_path.join("bundle-req.txt").write(pkg_lines)
script.pip('bundle', '-r', 'bundle-req.txt', 'test.pybundle')
build_bundle = script.scratch_path/"build-bundle"
src_bundle = script.scratch_path/"src-bundle"
assert not exists(build_bundle), "build-bundle/ dir still exists: %s" % build_bundle
assert not exists(src_bundle), "src-bundle/ dir still exists: %s" % src_bundle
env.assert_no_temp()
script.assert_no_temp()
# Make sure previously created src/ from editable still exists
assert exists(src), "expected src dir doesn't exist: %s" % src
import os
from tests.lib import reset_env, run_pip, get_env
from tests.lib import reset_env
def test_completion_for_bash():
"""
Test getting completion for bash shell
"""
reset_env()
script = reset_env()
bash_completion = """\
_pip_completion()
{
......@@ -16,7 +16,7 @@ _pip_completion()
}
complete -o default -F _pip_completion pip"""
result = run_pip('completion', '--bash')
result = script.pip('completion', '--bash')
assert bash_completion in result.stdout, 'bash completion is wrong'
......@@ -24,7 +24,7 @@ def test_completion_for_zsh():
"""
Test getting completion for zsh shell
"""
reset_env()
script = reset_env()
zsh_completion = """\
function _pip_completion {
local words cword
......@@ -36,7 +36,7 @@ function _pip_completion {
}
compctl -K _pip_completion pip"""
result = run_pip('completion', '--zsh')
result = script.pip('completion', '--zsh')
assert zsh_completion in result.stdout, 'zsh completion is wrong'
......@@ -44,9 +44,9 @@ def test_completion_for_unknown_shell():
"""
Test getting completion for an unknown shell
"""
reset_env()
script = reset_env()
error_msg = 'no such option: --myfooshell'
result = run_pip('completion', '--myfooshell', expect_error=True)
result = script.pip('completion', '--myfooshell', expect_error=True)
assert error_msg in result.stderr, 'tests for an unknown shell failed'
......@@ -54,25 +54,24 @@ def test_completion_alone():
"""
Test getting completion for none shell, just pip completion
"""
reset_env()
result = run_pip('completion', expect_error=True)
script = reset_env()
result = script.pip('completion', expect_error=True)
assert 'ERROR: You must pass --bash or --zsh' in result.stderr, \
'completion alone failed -- ' + result.stderr
def setup_completion(words, cword):
environ = os.environ.copy()
reset_env(environ)
script = reset_env(environ)
environ['PIP_AUTO_COMPLETE'] = '1'
environ['COMP_WORDS'] = words
environ['COMP_CWORD'] = cword
env = get_env()
# expect_error is True because autocomplete exists with 1 status code
result = env.run('python', '-c', 'import pip;pip.autocomplete()',
result = script.run('python', '-c', 'import pip;pip.autocomplete()',
expect_error=True)
return result, env
return result, script
def test_completion_for_un_snippet():
......
......@@ -2,7 +2,7 @@ import sys
import re
import textwrap
from doctest import OutputChecker, ELLIPSIS
from tests.lib import reset_env, run_pip, write_file, get_env, pyversion, pip_install_local
from tests.lib import reset_env
from tests.lib.local_repos import local_checkout, local_repo
......@@ -42,14 +42,14 @@ def test_freeze_basic():
currently it is not).
"""
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("initools-req.txt").write(textwrap.dedent("""\
simple==2.0
# and something else to test out:
simple2<=3.0
"""))
result = pip_install_local('-r', env.scratch_path/'initools-req.txt')
result = run_pip('freeze', expect_stderr=True)
result = script.pip_install_local('-r', script.scratch_path/'initools-req.txt')
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze
-- stdout: --------------------
......@@ -66,13 +66,13 @@ def test_freeze_svn():
#svn internally stores windows drives as uppercase; we'll match that.
checkout_path = checkout_path.replace('c:', 'C:')
env = reset_env()
result = env.run('svn', 'co', '-r10',
script = reset_env()
result = script.run('svn', 'co', '-r10',
local_repo('svn+http://svn.colorstudy.com/INITools/trunk'),
'initools-trunk')
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/ 'initools-trunk', expect_stderr=True)
result = run_pip('freeze', expect_stderr=True)
result = script.run('python', 'setup.py', 'develop',
cwd=script.scratch_path/ 'initools-trunk', expect_stderr=True)
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
......@@ -86,13 +86,13 @@ def test_freeze_git_clone():
Test freezing a Git clone.
"""
env = reset_env()
result = env.run('git', 'clone', local_repo('git+http://github.com/pypa/pip-test-package.git'), 'pip-test-package')
result = env.run('git', 'checkout', '7d654e66c8fa7149c165ddeffa5b56bc06619458',
cwd=env.scratch_path / 'pip-test-package', expect_stderr=True)
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path / 'pip-test-package')
result = run_pip('freeze', expect_stderr=True)
script = reset_env()
result = script.run('git', 'clone', local_repo('git+http://github.com/pypa/pip-test-package.git'), 'pip-test-package')
result = script.run('git', 'checkout', '7d654e66c8fa7149c165ddeffa5b56bc06619458',
cwd=script.scratch_path / 'pip-test-package', expect_stderr=True)
result = script.run('python', 'setup.py', 'develop',
cwd=script.scratch_path / 'pip-test-package')
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
......@@ -100,7 +100,7 @@ def test_freeze_git_clone():
...""" % local_checkout('git+http://github.com/pypa/pip-test-package.git'))
_check_output(result, expected)
result = run_pip('freeze', '-f',
result = script.pip('freeze', '-f',
'%s#egg=pip_test_package' % local_checkout('git+http://github.com/pypa/pip-test-package.git'),
expect_stderr=True)
expected = textwrap.dedent("""\
......@@ -117,15 +117,14 @@ def test_freeze_mercurial_clone():
Test freezing a Mercurial clone.
"""
reset_env()
env = get_env()
result = env.run('hg', 'clone',
script = reset_env()
result = script.run('hg', 'clone',
'-r', 'c9963c111e7c',
local_repo('hg+http://bitbucket.org/pypa/pip-test-package'),
'pip-test-package')
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/'pip-test-package', expect_stderr=True)
result = run_pip('freeze', expect_stderr=True)
result = script.run('python', 'setup.py', 'develop',
cwd=script.scratch_path/'pip-test-package', expect_stderr=True)
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
......@@ -133,7 +132,7 @@ def test_freeze_mercurial_clone():
...""" % local_checkout('hg+http://bitbucket.org/pypa/pip-test-package'))
_check_output(result, expected)
result = run_pip('freeze', '-f',
result = script.pip('freeze', '-f',
'%s#egg=pip_test_package' % local_checkout('hg+http://bitbucket.org/pypa/pip-test-package'),
expect_stderr=True)
expected = textwrap.dedent("""\
......@@ -155,14 +154,13 @@ def test_freeze_bazaar_clone():
#bzr internally stores windows drives as uppercase; we'll match that.
checkout_pathC = checkout_path.replace('c:', 'C:')
reset_env()
env = get_env()
result = env.run('bzr', 'checkout', '-r', '174',
script = reset_env()
result = script.run('bzr', 'checkout', '-r', '174',
local_repo('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
'django-wikiapp')
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/'django-wikiapp')
result = run_pip('freeze', expect_stderr=True)
result = script.run('python', 'setup.py', 'develop',
cwd=script.scratch_path/'django-wikiapp')
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
......@@ -170,7 +168,7 @@ def test_freeze_bazaar_clone():
...""" % checkout_pathC)
_check_output(result, expected)
result = run_pip('freeze', '-f',
result = script.pip('freeze', '-f',
'%s/#egg=django-wikiapp' % checkout_path,
expect_stderr=True)
expected = textwrap.dedent("""\
......@@ -187,9 +185,9 @@ def test_freeze_with_local_option():
Test that wsgiref (from global site-packages) is reported normally, but not with --local.
"""
reset_env()
result = run_pip('install', 'initools==0.2')
result = run_pip('freeze', expect_stderr=True)
script = reset_env()
result = script.pip('install', 'initools==0.2')
result = script.pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
......@@ -204,7 +202,7 @@ def test_freeze_with_local_option():
# _check_output(result, expected)
result = run_pip('freeze', '--local', expect_stderr=True)
result = script.pip('freeze', '--local', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze --local
-- stdout: --------------------
......@@ -218,7 +216,7 @@ def test_freeze_with_requirement_option():
Test that new requirements are created correctly with --requirement hints
"""
reset_env()
script = reset_env()
ignores = textwrap.dedent("""\
# Unchanged requirements below this line
-r ignore.txt
......@@ -231,13 +229,13 @@ def test_freeze_with_requirement_option():
--find-links http://ignore
--index-url http://ignore
""")
write_file('hint.txt', textwrap.dedent("""\
script.scratch_path.join("hint.txt").write(textwrap.dedent("""\
INITools==0.1
NoExist==4.2
""") + ignores)
result = run_pip('install', 'initools==0.2')
result = pip_install_local('simple')
result = run_pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
result = script.pip('install', 'initools==0.2')
result = script.pip_install_local('simple')
result = script.pip('freeze', '--requirement', 'hint.txt', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze --requirement hint.txt
-- stderr: --------------------
......
......@@ -6,7 +6,7 @@ from pip.basecommand import ERROR, SUCCESS
from pip.commands.help import HelpCommand
from pip.commands import commands
from mock import Mock
from tests.lib import run_pip, reset_env
from tests.lib import reset_env
def test_run_method_should_return_sucess_when_finds_command_name():
......@@ -47,8 +47,8 @@ def test_help_command_should_exit_status_ok_when_command_exists():
"""
Test `help` command for existing command
"""
reset_env()
result = run_pip('help', 'freeze')
script = reset_env()
result = script.pip('help', 'freeze')
assert result.returncode == SUCCESS
......@@ -56,8 +56,8 @@ def test_help_command_should_exit_status_ok_when_no_command_is_specified():
"""
Test `help` command for no command
"""
reset_env()
result = run_pip('help')
script = reset_env()
result = script.pip('help')
assert result.returncode == SUCCESS
......@@ -65,18 +65,18 @@ def test_help_command_should_exit_status_error_when_command_does_not_exist():
"""
Test `help` command for non-existing command
"""
reset_env()
result = run_pip('help', 'mycommand', expect_error=True)
script = reset_env()
result = script.pip('help', 'mycommand', expect_error=True)
assert result.returncode == ERROR
def test_help_commands_equally_functional():
"""
Test if `pip help` and 'pip --help' behave the same way.
"""
reset_env()
script = reset_env()
results = list(map(run_pip, ('help', '--help')))
results.append(run_pip())
results = list(map(script.pip, ('help', '--help')))
results.append(script.pip())
out = map(lambda x: x.stdout, results)
ret = map(lambda x: x.returncode, results)
......@@ -87,7 +87,5 @@ def test_help_commands_equally_functional():
for name, cls in commands.items():
if cls.hidden: continue
assert run_pip('help', name).stdout == \
run_pip(name, '--help').stdout
assert script.pip('help', name).stdout == \
script.pip(name, '--help').stdout
此差异已折叠。
import os
from tests.lib import reset_env, pip_install_local, packages
from tests.lib import reset_env, packages
def test_install_pybundle():
"""
Test intalling a *.pybundle file
"""
env = reset_env()
result = pip_install_local(os.path.join(packages, 'simplebundle.pybundle'), expect_temp=True)
script = reset_env()
result = script.pip_install_local(os.path.join(packages, 'simplebundle.pybundle'), expect_temp=True)
result.assert_installed('simple', editable=False)
result.assert_installed('simple2', editable=False)
import os
import textwrap
from os.path import abspath, exists, join
from tests.lib import (tests_data, reset_env, run_pip, pip_install_local,
write_file, mkdir, path_to_url, find_links)
from tests.lib import tests_data, reset_env, find_links
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path
......@@ -11,21 +10,21 @@ def test_cleanup_after_install():
"""
Test clean up after installing a package.
"""
env = reset_env()
run_pip('install', '--no-index', '--find-links=%s' % find_links, 'simple')
build = env.venv_path/"build"
src = env.venv_path/"src"
script = reset_env()
script.pip('install', '--no-index', '--find-links=%s' % find_links, 'simple')
build = script.venv_path/"build"
src = script.venv_path/"src"
assert not exists(build), "build/ dir still exists: %s" % build
assert not exists(src), "unexpected src/ dir exists: %s" % src
env.assert_no_temp()
script.assert_no_temp()
def test_no_clean_option_blocks_cleaning_after_install():
"""
Test --no-clean option blocks cleaning after install
"""
env = reset_env()
result = run_pip('install', '--no-clean', '--no-index', '--find-links=%s' % find_links, 'simple')
build = env.venv_path/'build'/'simple'
script = reset_env()
result = script.pip('install', '--no-clean', '--no-index', '--find-links=%s' % find_links, 'simple')
build = script.venv_path/'build'/'simple'
assert exists(build), "build/simple should still exist %s" % str(result)
......@@ -34,17 +33,17 @@ def test_cleanup_after_install_editable_from_hg():
Test clean up after cloning from Mercurial.
"""
env = reset_env()
run_pip('install',
script = reset_env()
script.pip('install',
'-e',
'%s#egg=ScriptTest' %
local_checkout('hg+https://bitbucket.org/ianb/scripttest'),
expect_error=True)
build = env.venv_path/'build'
src = env.venv_path/'src'
build = script.venv_path/'build'
src = script.venv_path/'src'
assert not exists(build), "build/ dir still exists: %s" % build
assert exists(src), "expected src/ dir doesn't exist: %s" % src
env.assert_no_temp()
script.assert_no_temp()
def test_cleanup_after_install_from_local_directory():
......@@ -52,26 +51,26 @@ def test_cleanup_after_install_from_local_directory():
Test clean up after installing from a local directory.
"""
env = reset_env()
script = reset_env()
to_install = abspath(join(tests_data, 'packages', 'FSPkg'))
run_pip('install', to_install, expect_error=False)
build = env.venv_path/'build'
src = env.venv_path/'src'
script.pip('install', to_install, expect_error=False)
build = script.venv_path/'build'
src = script.venv_path/'src'
assert not exists(build), "unexpected build/ dir exists: %s" % build
assert not exists(src), "unexpected src/ dir exist: %s" % src
env.assert_no_temp()
script.assert_no_temp()
def test_no_install_and_download_should_not_leave_build_dir():
"""
It should remove build/ dir if it was pip that created
"""
env = reset_env()
mkdir('downloaded_packages')
assert not os.path.exists(env.venv_path/'/build')
result = run_pip('install', '--no-install', 'INITools==0.2', '-d', 'downloaded_packages')
script = reset_env()
script.scratch_path.join("downloaded_packages").mkdir()
assert not os.path.exists(script.venv_path/'/build')
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(env.venv_path/'/build'), "build/ dir should be deleted"
assert not os.path.exists(script.venv_path/'/build'), "build/ dir should be deleted"
def test_cleanup_req_satisifed_no_name():
......@@ -85,61 +84,58 @@ def test_cleanup_req_satisifed_no_name():
# 2) parent-0.1.tar.gz
dist = abspath(join(tests_data, 'packages', 'parent-0.1.tar.gz'))
env = reset_env()
result = run_pip('install', dist)
result = run_pip('install', dist)
build = env.venv_path/'build'
script = reset_env()
result = script.pip('install', dist)
result = script.pip('install', dist)
build = script.venv_path/'build'
assert not exists(build), "unexpected build/ dir exists: %s" % build
env.assert_no_temp()
script.assert_no_temp()
def test_download_should_not_delete_existing_build_dir():
"""
It should not delete build/ if existing before run the command
"""
env = reset_env()
mkdir(env.venv_path/'build')
f = open(env.venv_path/'build'/'somefile.txt', 'w')
f.write('I am not empty!')
f.close()
run_pip('install', '--no-install', 'INITools==0.2', '-d', '.')
f = open(env.venv_path/'build'/'somefile.txt')
content = f.read()
f.close()
assert os.path.exists(env.venv_path/'build'), "build/ should be left if it exists before pip run"
script = reset_env()
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()
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"
assert ['somefile.txt'] == os.listdir(env.venv_path/'build')
assert ['somefile.txt'] == os.listdir(script.venv_path/'build')
def test_cleanup_after_install_exception():
"""
Test clean up after a 'setup.py install' exception.
"""
env = reset_env()
script = reset_env()
#broken==0.2broken fails during install; see packages readme file
result = run_pip('install', '-f', find_links, '--no-index', 'broken==0.2broken', expect_error=True)
build = env.venv_path/'build'
result = script.pip('install', '-f', find_links, '--no-index', 'broken==0.2broken', expect_error=True)
build = script.venv_path/'build'
assert not exists(build), "build/ dir still exists: %s" % result.stdout
env.assert_no_temp()
script.assert_no_temp()
def test_cleanup_after_egg_info_exception():
"""
Test clean up after a 'setup.py egg_info' exception.
"""
env = reset_env()
script = reset_env()
#brokenegginfo fails during egg_info; see packages readme file
result = run_pip('install', '-f', find_links, '--no-index', 'brokenegginfo==0.1', expect_error=True)
build = env.venv_path/'build'
result = script.pip('install', '-f', find_links, '--no-index', 'brokenegginfo==0.1', expect_error=True)
build = script.venv_path/'build'
assert not exists(build), "build/ dir still exists: %s" % result.stdout
env.assert_no_temp()
script.assert_no_temp()
def test_cleanup_prevented_upon_build_dir_exception():
"""
Test no cleanup occurs after a PreviousBuildDirError
"""
env = reset_env()
build = env.venv_path/'build'/'simple'
script = reset_env()
build = script.venv_path/'build'/'simple'
os.makedirs(build)
write_file("setup.py", "#", dest=build)
result = run_pip('install', '-f', find_links, '--no-index', 'simple', expect_error=True)
build.join("setup.py").write("#")
result = script.pip('install', '-f', find_links, '--no-index', 'simple', expect_error=True)
assert "pip can't proceed" in result.stdout, result.stdout
assert exists(build)
......@@ -3,8 +3,7 @@ Tests for compatibility workarounds.
"""
import os
from tests.lib import (tests_data, reset_env, run_pip, pyversion,
assert_all_changes)
from tests.lib import tests_data, reset_env, pyversion, assert_all_changes
def test_debian_egg_name_workaround():
......@@ -18,11 +17,11 @@ def test_debian_egg_name_workaround():
https://bitbucket.org/ianb/pip/issue/104/pip-uninstall-on-ubuntu-linux
"""
env = reset_env()
result = run_pip('install', 'INITools==0.2', expect_error=True)
script = reset_env()
result = script.pip('install', 'INITools==0.2', expect_error=True)
egg_info = os.path.join(
env.site_packages, "INITools-0.2-py%s.egg-info" % pyversion)
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,
......@@ -30,19 +29,19 @@ def test_debian_egg_name_workaround():
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(env.site_packages, "INITools-0.2.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(env.root_path, egg_info)
full_egg_info = os.path.join(script.base_path, egg_info)
assert os.path.isdir(full_egg_info)
full_mangled = os.path.join(env.root_path, mangled)
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 = run_pip("uninstall", "INITools", "-y")
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
result2 = script.pip("uninstall", "INITools", "-y")
assert_all_changes(result, result2, [script.venv/'build', 'cache'])
def test_setup_py_with_dos_line_endings():
......@@ -51,6 +50,6 @@ def test_setup_py_with_dos_line_endings():
Refs https://github.com/pypa/pip/issues/237
"""
reset_env()
script = reset_env()
to_install = os.path.abspath(os.path.join(tests_data, 'packages', 'LineEndings'))
run_pip('install', to_install, expect_error=False)
script.pip('install', to_install, expect_error=False)
import os
import tempfile
import textwrap
from tests.lib import (reset_env, run_pip, clear_environ, write_file, path_to_url,
find_links)
from tests.lib import reset_env, clear_environ, path_to_url, find_links
def test_options_from_env_vars():
......@@ -12,8 +12,8 @@ def test_options_from_env_vars():
"""
environ = clear_environ(os.environ.copy())
environ['PIP_NO_INDEX'] = '1'
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Ignoring indexes:" in result.stdout, str(result)
assert "DistributionNotFound: No distributions at all found for INITools" in result.stdout
......@@ -25,11 +25,11 @@ def test_command_line_options_override_env_vars():
"""
environ = clear_environ(os.environ.copy())
environ['PIP_INDEX_URL'] = 'http://b.pypi.python.org/simple/'
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Getting page http://b.pypi.python.org/simple/INITools" in result.stdout
reset_env(environ)
result = run_pip('install', '-vvv', '--index-url', 'http://download.zope.org/ppix', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', '--index-url', 'http://download.zope.org/ppix', 'INITools', expect_error=True)
assert "b.pypi.python.org" not in result.stdout
assert "Getting page http://download.zope.org/ppix" in result.stdout
......@@ -52,20 +52,20 @@ def test_env_vars_override_config_file():
def _test_env_vars_override_config_file(config_file):
environ = clear_environ(os.environ.copy())
environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it
reset_env(environ)
script = reset_env(environ)
# It's important that we test this particular config value ('no-index')
# because their is/was a bug which only shows up in cases in which
# 'config-item' and 'config_item' hash to the same value modulo the size
# of the config dictionary.
write_file(config_file, textwrap.dedent("""\
(script.scratch_path/config_file).write(textwrap.dedent("""\
[global]
no-index = 1
"""))
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "DistributionNotFound: No distributions at all found for INITools" in result.stdout
environ['PIP_NO_INDEX'] = '0'
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Successfully installed INITools" in result.stdout
......@@ -76,11 +76,11 @@ def test_command_line_append_flags():
"""
environ = clear_environ(os.environ.copy())
environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com'
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout
reset_env(environ)
result = run_pip('install', '-vvv', '--find-links', find_links, 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', '--find-links', find_links, 'INITools', expect_error=True)
assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout
assert "Skipping link %s" % find_links in result.stdout
......@@ -92,8 +92,8 @@ def test_command_line_appends_correctly():
"""
environ = clear_environ(os.environ.copy())
environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com %s' % find_links
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
script = reset_env(environ)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout, result.stdout
assert "Skipping link %s" % find_links in result.stdout
......@@ -118,23 +118,23 @@ def test_config_file_override_stack():
def _test_config_file_override_stack(config_file):
environ = clear_environ(os.environ.copy())
environ['PIP_CONFIG_FILE'] = config_file # set this to make pip load it
reset_env(environ)
write_file(config_file, textwrap.dedent("""\
script = reset_env(environ)
(script.scratch_path/config_file).write(textwrap.dedent("""\
[global]
index-url = http://download.zope.org/ppix
"""))
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Getting page http://download.zope.org/ppix/INITools" in result.stdout
reset_env(environ)
write_file(config_file, textwrap.dedent("""\
script = reset_env(environ)
(script.scratch_path/config_file).write(textwrap.dedent("""\
[global]
index-url = http://download.zope.org/ppix
[install]
index-url = http://pypi.appspot.com/
"""))
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
result = script.pip('install', '-vvv', 'INITools', expect_error=True)
assert "Getting page http://pypi.appspot.com/INITools" in result.stdout
result = run_pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True)
result = script.pip('install', '-vvv', '--index-url', 'http://pypi.python.org/simple', 'INITools', expect_error=True)
assert "Getting page http://download.zope.org/ppix/INITools" not in result.stdout
assert "Getting page http://pypi.appspot.com/INITools" not in result.stdout
assert "Getting page http://pypi.python.org/simple/INITools" in result.stdout
......
import textwrap
from tests.lib import reset_env, run_pip, write_file
from tests.lib import reset_env
from tests.lib.path import Path
......@@ -9,10 +9,10 @@ def test_download_if_requested():
It should download (in the scratch path) and not install if requested.
"""
env = reset_env()
result = run_pip('install', 'INITools==0.1', '-d', '.', expect_error=True)
script = reset_env()
result = script.pip('install', 'INITools==0.1', '-d', '.', expect_error=True)
assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
assert script.site_packages/ 'initools' not in result.files_created
def test_download_wheel():
......@@ -22,12 +22,12 @@ def test_download_wheel():
--find-links has a bug https://github.com/pypa/pip/issues/1111
"""
env = reset_env()
result = run_pip('install', '--use-wheel',
script = reset_env()
result = script.pip('install', '--use-wheel',
'-f', 'https://bitbucket.org/pypa/pip-test-package/downloads',
'-d', '.', 'pip-test-package')
assert Path('scratch')/ 'pip_test_package-0.1.1-py2.py3-none-any.whl' in result.files_created
assert env.site_packages/ 'piptestpackage' not in result.files_created
assert script.site_packages/ 'piptestpackage' not in result.files_created
def test_single_download_from_requirements_file():
......@@ -35,13 +35,13 @@ def test_single_download_from_requirements_file():
It should support download (in the scratch path) from PyPi from a requirements file
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""
script = reset_env()
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""
INITools==0.1
"""))
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
result = script.pip('install', '-r', script.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
assert script.site_packages/ 'initools' not in result.files_created
def test_download_should_download_dependencies():
......@@ -49,38 +49,38 @@ def test_download_should_download_dependencies():
It should download dependencies (in the scratch path)
"""
env = reset_env()
result = run_pip('install', 'Paste[openid]==1.7.5.1', '-d', '.', expect_error=True)
script = reset_env()
result = script.pip('install', 'Paste[openid]==1.7.5.1', '-d', '.', expect_error=True)
assert Path('scratch')/ 'Paste-1.7.5.1.tar.gz' in result.files_created
openid_tarball_prefix = str(Path('scratch')/ 'python-openid-')
assert any(path.startswith(openid_tarball_prefix) for path in result.files_created)
assert env.site_packages/ 'openid' not in result.files_created
assert script.site_packages/ 'openid' not in result.files_created
def test_download_should_skip_existing_files():
"""
It should not download files already existing in the scratch dir
"""
env = reset_env()
script = reset_env()
write_file('test-req.txt', textwrap.dedent("""
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""
INITools==0.1
"""))
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
result = script.pip('install', '-r', script.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
assert Path('scratch')/ 'INITools-0.1.tar.gz' in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
assert script.site_packages/ 'initools' not in result.files_created
# adding second package to test-req.txt
write_file('test-req.txt', textwrap.dedent("""
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""
INITools==0.1
python-openid==2.2.5
"""))
# only the second package should be downloaded
result = run_pip('install', '-r', env.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
result = script.pip('install', '-r', script.scratch_path/ 'test-req.txt', '-d', '.', expect_error=True)
openid_tarball_prefix = str(Path('scratch')/ 'python-openid-')
assert any(path.startswith(openid_tarball_prefix) for path in result.files_created)
assert Path('scratch')/ 'INITools-0.1.tar.gz' not in result.files_created
assert env.site_packages/ 'initools' not in result.files_created
assert env.site_packages/ 'openid' not in result.files_created
assert script.site_packages/ 'initools' not in result.files_created
assert script.site_packages/ 'openid' not in result.files_created
from os.path import join
from tests.lib import reset_env, run_pip
from tests.lib import reset_env
def test_simple_extras_install_from_pypi():
"""
Test installing a package from PyPI using extras dependency Paste[openid].
"""
e = reset_env()
result = run_pip('install', 'Paste[openid]==1.7.5.1', expect_stderr=True)
initools_folder = e.site_packages / 'openid'
script = reset_env()
result = script.pip('install', 'Paste[openid]==1.7.5.1', expect_stderr=True)
initools_folder = script.site_packages / 'openid'
assert initools_folder in result.files_created, result.files_created
......@@ -17,11 +17,11 @@ def test_no_extras_uninstall():
"""
No extras dependency gets uninstalled when the root package is uninstalled
"""
env = reset_env()
result = run_pip('install', 'Paste[openid]==1.7.5.1', expect_stderr=True)
assert join(env.site_packages, 'paste') in result.files_created, sorted(result.files_created.keys())
assert join(env.site_packages, 'openid') in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('uninstall', 'Paste', '-y')
script = reset_env()
result = script.pip('install', 'Paste[openid]==1.7.5.1', expect_stderr=True)
assert join(script.site_packages, 'paste') in result.files_created, sorted(result.files_created.keys())
assert join(script.site_packages, 'openid') in result.files_created, sorted(result.files_created.keys())
result2 = script.pip('uninstall', 'Paste', '-y')
# openid should not be uninstalled
initools_folder = env.site_packages / 'openid'
initools_folder = script.site_packages / 'openid'
assert not initools_folder in result2.files_deleted, result.files_deleted
......@@ -2,41 +2,41 @@ import os
import textwrap
from pip.backwardcompat import urllib
from tests.lib import (reset_env, run_pip, pyversion, tests_data, write_file,
path_to_url)
from tests.lib import reset_env, pyversion, tests_data, path_to_url
def test_find_links_relative_path():
"""Test find-links as a relative path."""
e = reset_env()
result = run_pip(
script = reset_env()
result = script.pip(
'install',
'parent==0.1',
'--no-index',
'--find-links',
'packages/',
cwd=tests_data)
egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
initools_folder = e.site_packages / 'parent'
egg_info_folder = script.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
initools_folder = script.site_packages / 'parent'
assert egg_info_folder in result.files_created, str(result)
assert initools_folder in result.files_created, str(result)
def test_find_links_requirements_file_relative_path():
"""Test find-links as a relative path to a reqs file."""
e = reset_env()
write_file('test-req.txt', textwrap.dedent("""
script = reset_env()
script.scratch_path.join("test-req.txt").write(textwrap.dedent("""
--no-index
--find-links=../../../data/packages/
parent==0.1
"""))
result = run_pip(
result = script.pip(
'install',
'-r',
e.scratch_path / "test-req.txt",
script.scratch_path / "test-req.txt",
cwd=tests_data)
egg_info_folder = e.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
initools_folder = e.site_packages / 'parent'
egg_info_folder = script.site_packages / 'parent-0.1-py%s.egg-info' % pyversion
initools_folder = script.site_packages / 'parent'
assert egg_info_folder in result.files_created, str(result)
assert initools_folder in result.files_created, str(result)
......@@ -45,10 +45,10 @@ def test_install_from_file_index_hash_link():
"""
Test that a pkg can be installed from a file:// index using a link with a hash
"""
env = reset_env()
script = reset_env()
index_url = path_to_url(os.path.join(tests_data, 'indexes', 'simple'))
result = run_pip('install', '-i', index_url, 'simple==1.0')
egg_info_folder = env.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
result = script.pip('install', '-i', index_url, 'simple==1.0')
egg_info_folder = script.site_packages / 'simple-1.0-py%s.egg-info' % pyversion
assert egg_info_folder in result.files_created, str(result)
......@@ -57,7 +57,7 @@ def test_file_index_url_quoting():
Test url quoting of file index url with a space
"""
index_url = path_to_url(os.path.join(tests_data, 'indexes', urllib.quote('in dex')))
env = reset_env()
result = run_pip('install', '-vvv', '--index-url', index_url, 'simple', expect_error=False)
assert (env.site_packages/'simple') in result.files_created, str(result.stdout)
assert (env.site_packages/'simple-1.0-py%s.egg-info' % pyversion) in result.files_created, str(result)
script = reset_env()
result = script.pip('install', '-vvv', '--index-url', index_url, 'simple', expect_error=False)
assert (script.site_packages/'simple') in result.files_created, str(result.stdout)
assert (script.site_packages/'simple-1.0-py%s.egg-info' % pyversion) in result.files_created, str(result)
......@@ -7,8 +7,8 @@ from mock import patch
from pip.backwardcompat import urllib
from pip.req import Requirements, parse_editable, parse_requirements
from tests.lib import (reset_env, run_pip, write_file, pyversion, tests_data,
path_to_url, find_links)
from tests.lib import reset_env, pyversion, tests_data, path_to_url, find_links
from tests.lib.local_repos import local_checkout
from tests.lib.path import Path
......@@ -19,18 +19,18 @@ def test_requirements_file():
"""
other_lib_name, other_lib_version = 'anyjson', '0.3'
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("initools-req.txt").write(textwrap.dedent("""\
INITools==0.2
# and something else to test out:
%s<=%s
""" % (other_lib_name, other_lib_version)))
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
assert env.site_packages/'initools' in result.files_created
assert result.files_created[env.site_packages/other_lib_name].dir
result = script.pip('install', '-r', script.scratch_path / 'initools-req.txt')
assert script.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
assert script.site_packages/'initools' in result.files_created
assert result.files_created[script.site_packages/other_lib_name].dir
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
assert result.files_created[env.site_packages/fn].dir
assert result.files_created[script.site_packages/fn].dir
def test_schema_check_in_requirements_file():
......@@ -38,13 +38,13 @@ def test_schema_check_in_requirements_file():
Test installing from a requirements file with an invalid vcs schema..
"""
env = reset_env()
write_file('file-egg-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("file-egg-req.txt").write(textwrap.dedent("""\
git://github.com/alex/django-fixture-generator.git#egg=fixture_generator
"""))
with pytest.raises(AssertionError):
run_pip("install", "-vvv", "-r", env.scratch_path / "file-egg-req.txt")
script.pip("install", "-vvv", "-r", script.scratch_path / "file-egg-req.txt")
def test_relative_requirements_file():
......@@ -53,13 +53,13 @@ def test_relative_requirements_file():
"""
url = path_to_url(os.path.join(tests_data, 'packages', '..', 'packages', 'FSPkg')) + '#egg=FSPkg'
env = reset_env()
write_file('file-egg-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("file-egg-req.txt").write(textwrap.dedent("""\
%s
""" % url))
result = run_pip('install', '-vvv', '-r', env.scratch_path / 'file-egg-req.txt')
assert (env.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
assert (env.site_packages/'fspkg') in result.files_created, str(result.stdout)
result = script.pip('install', '-vvv', '-r', script.scratch_path / 'file-egg-req.txt')
assert (script.site_packages/'FSPkg-0.1dev-py%s.egg-info' % pyversion) in result.files_created, str(result)
assert (script.site_packages/'fspkg') in result.files_created, str(result.stdout)
def test_multiple_requirements_files():
......@@ -68,30 +68,30 @@ def test_multiple_requirements_files():
"""
other_lib_name, other_lib_version = 'anyjson', '0.3'
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("initools-req.txt").write(textwrap.dedent("""\
-e %s@10#egg=INITools-dev
-r %s-req.txt""" % (local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
other_lib_name)))
write_file('%s-req.txt' % other_lib_name, textwrap.dedent("""\
script.scratch_path.join("%s-req.txt" % other_lib_name).write(textwrap.dedent("""\
%s<=%s
""" % (other_lib_name, other_lib_version)))
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
assert result.files_created[env.site_packages/other_lib_name].dir
result = script.pip('install', '-r', script.scratch_path / 'initools-req.txt')
assert result.files_created[script.site_packages/other_lib_name].dir
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
assert result.files_created[env.site_packages/fn].dir
assert env.venv/'src'/'initools' in result.files_created
assert result.files_created[script.site_packages/fn].dir
assert script.venv/'src'/'initools' in result.files_created
def test_respect_order_in_requirements_file():
env = reset_env()
write_file('frameworks-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("frameworks-req.txt").write(textwrap.dedent("""\
parent
child
simple
"""))
result = run_pip('install', '--no-index', '-f', find_links, '-r', env.scratch_path / 'frameworks-req.txt')
result = script.pip('install', '--no-index', '-f', find_links, '-r', script.scratch_path / 'frameworks-req.txt')
downloaded = [line for line in result.stdout.split('\n')
if 'Downloading/unpacking' in line]
......@@ -106,13 +106,9 @@ def test_respect_order_in_requirements_file():
def test_install_local_editable_with_extras():
env = reset_env()
script = reset_env()
to_install = os.path.abspath(os.path.join(tests_data, 'packages', 'LocalExtras'))
res = run_pip('install', '-e', to_install + '[bar]', expect_error=False)
assert env.site_packages/'easy-install.pth' in res.files_updated, str(result)
assert env.site_packages/'LocalExtras.egg-link' in res.files_created, str(result)
assert env.site_packages/'simple' in res.files_created, str(result)
res = script.pip('install', '-e', to_install + '[bar]', expect_error=False)
assert script.site_packages/'easy-install.pth' in res.files_updated, str(result)
assert script.site_packages/'LocalExtras.egg-link' in res.files_created, str(result)
assert script.site_packages/'simple' in res.files_created, str(result)
......@@ -6,9 +6,9 @@ from os.path import join
import pytest
from tests.lib import (reset_env, run_pip, assert_all_changes, src_folder,
write_file, pyversion, _create_test_package, pip_install_local,
_change_test_package_version, path_to_url, find_links)
from tests.lib import (reset_env, assert_all_changes, src_folder, pyversion,
_create_test_package, _change_test_package_version,
find_links)
from tests.lib.local_repos import local_checkout
......@@ -17,9 +17,9 @@ def test_no_upgrade_unless_requested():
No upgrade if not specifically requested.
"""
reset_env()
run_pip('install', 'INITools==0.1', expect_error=True)
result = run_pip('install', 'INITools', expect_error=True)
script = reset_env()
script.pip('install', 'INITools==0.1', expect_error=True)
result = script.pip('install', 'INITools', expect_error=True)
assert not result.files_created, 'pip install INITools upgraded when it should not have'
......@@ -28,12 +28,12 @@ def test_upgrade_to_specific_version():
It does upgrade to specific version requested.
"""
env = reset_env()
run_pip('install', 'INITools==0.1', expect_error=True)
result = run_pip('install', 'INITools==0.2', expect_error=True)
script = reset_env()
script.pip('install', 'INITools==0.1', expect_error=True)
result = script.pip('install', 'INITools==0.2', expect_error=True)
assert result.files_created, 'pip install with specific version did not upgrade'
assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion in result.files_deleted
assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
assert script.site_packages/'INITools-0.1-py%s.egg-info' % pyversion in result.files_deleted
assert script.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
def test_upgrade_if_requested():
......@@ -41,11 +41,11 @@ def test_upgrade_if_requested():
And it does upgrade if requested.
"""
env = reset_env()
run_pip('install', 'INITools==0.1', expect_error=True)
result = run_pip('install', '--upgrade', 'INITools', expect_error=True)
script = reset_env()
script.pip('install', 'INITools==0.1', expect_error=True)
result = script.pip('install', '--upgrade', 'INITools', expect_error=True)
assert result.files_created, 'pip install --upgrade did not upgrade'
assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
assert script.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_upgrade_with_newest_already_installed():
......@@ -54,9 +54,9 @@ def test_upgrade_with_newest_already_installed():
not be reinstalled and the user should be informed.
"""
env = reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple')
result = run_pip('install', '--upgrade', '-f', find_links, '--no-index', 'simple')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple')
result = script.pip('install', '--upgrade', '-f', find_links, '--no-index', 'simple')
assert not result.files_created, 'simple upgraded when it should not have'
assert 'already up-to-date' in result.stdout, result.stdout
......@@ -67,13 +67,13 @@ def test_upgrade_force_reinstall_newest():
version if --force-reinstall is supplied.
"""
env = reset_env()
result = run_pip('install', 'INITools')
assert env.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('install', '--upgrade', '--force-reinstall', 'INITools')
script = reset_env()
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 = run_pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [env.venv/'build', 'cache'])
result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [script.venv/'build', 'cache'])
def test_uninstall_before_upgrade():
......@@ -81,13 +81,13 @@ 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)
script = reset_env()
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 = run_pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [env.venv/'build', 'cache'])
result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [script.venv/'build', 'cache'])
def test_uninstall_before_upgrade_from_url():
......@@ -95,13 +95,13 @@ def test_uninstall_before_upgrade_from_url():
Automatic uninstall-before-upgrade from URL.
"""
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', 'http://pypi.python.org/packages/source/I/INITools/INITools-0.3.tar.gz', expect_error=True)
script = reset_env()
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 = run_pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [env.venv/'build', 'cache'])
result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [script.venv/'build', 'cache'])
def test_upgrade_to_same_version_from_url():
......@@ -110,13 +110,13 @@ def test_upgrade_to_same_version_from_url():
need to uninstall and reinstall if --upgrade is not specified.
"""
env = reset_env()
result = run_pip('install', 'INITools==0.3', expect_error=True)
assert env.site_packages/ 'initools' in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('install', 'http://pypi.python.org/packages/source/I/INITools/INITools-0.3.tar.gz', expect_error=True)
script = reset_env()
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 = run_pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [env.venv/'build', 'cache'])
result3 = script.pip('uninstall', 'initools', '-y', expect_error=True)
assert_all_changes(result, result3, [script.venv/'build', 'cache'])
def test_upgrade_from_reqs_file():
......@@ -124,21 +124,21 @@ def test_upgrade_from_reqs_file():
Upgrade from a requirements file.
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""\
script = reset_env()
script.scratch_path.join("test-req.txt").write(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("""\
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
"""))
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'])
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'])
def test_uninstall_rollback():
......@@ -147,13 +147,13 @@ def test_uninstall_rollback():
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)
script = reset_env()
result = script.pip('install', '-f', 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', 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'])
assert script.run('python', '-c', "import broken; print(broken.VERSION)").stdout == '0.1\n'
assert_all_changes(result.files_after, result2, [script.venv/'build', 'pip-log.txt'])
# Issue #530 - temporarily disable flaky test
@pytest.mark.skipif
......@@ -162,14 +162,14 @@ def test_editable_git_upgrade():
Test installing an editable git package from a repository, upgrading the repository,
installing again, and check it gets the newer version
"""
env = reset_env()
version_pkg_path = _create_test_package(env)
run_pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
version = env.run('version_pkg')
script = reset_env()
version_pkg_path = _create_test_package(script)
script.pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
version = script.run('version_pkg')
assert '0.1' in version.stdout
_change_test_package_version(env, version_pkg_path)
run_pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
version2 = env.run('version_pkg')
_change_test_package_version(script, version_pkg_path)
script.pip('install', '-e', '%s#egg=version_pkg' % ('git+file://' + version_pkg_path))
version2 = script.run('version_pkg')
assert 'some different version' in version2.stdout, "Output: %s" % (version2.stdout)
......@@ -178,12 +178,12 @@ def test_should_not_install_always_from_cache():
If there is an old cached package, pip should download the newer version
Related to issue #175
"""
env = reset_env()
run_pip('install', 'INITools==0.2', expect_error=True)
run_pip('uninstall', '-y', 'INITools')
result = run_pip('install', 'INITools==0.1', expect_error=True)
assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion not in result.files_created
assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion in result.files_created
script = reset_env()
script.pip('install', 'INITools==0.2', expect_error=True)
script.pip('uninstall', '-y', 'INITools')
result = script.pip('install', 'INITools==0.1', expect_error=True)
assert script.site_packages/'INITools-0.2-py%s.egg-info' % pyversion not in result.files_created
assert script.site_packages/'INITools-0.1-py%s.egg-info' % pyversion in result.files_created
def test_install_with_ignoreinstalled_requested():
......@@ -191,30 +191,30 @@ def test_install_with_ignoreinstalled_requested():
It installs package if ignore installed is set.
"""
env = reset_env()
run_pip('install', 'INITools==0.1', expect_error=True)
result = run_pip('install', '-I', 'INITools', expect_error=True)
script = reset_env()
script.pip('install', 'INITools==0.1', expect_error=True)
result = script.pip('install', '-I', 'INITools', expect_error=True)
assert result.files_created, 'pip install -I did not install'
assert env.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
assert script.site_packages/'INITools-0.1-py%s.egg-info' % pyversion not in result.files_created
def test_upgrade_vcs_req_with_no_dists_found():
"""It can upgrade a VCS requirement that has no distributions otherwise."""
reset_env()
script = reset_env()
req = "%s#egg=pip-test-package" % local_checkout(
"git+http://github.com/pypa/pip-test-package.git")
run_pip("install", req)
result = run_pip("install", "-U", req)
script.pip("install", req)
result = script.pip("install", "-U", req)
assert not result.returncode
def test_upgrade_vcs_req_with_dist_found():
"""It can upgrade a VCS requirement that has distributions on the index."""
reset_env()
script = reset_env()
# TODO(pnasrat) Using local_checkout fails on windows - oddness with the test path urls/git.
req = "%s#egg=virtualenv" % "git+git://github.com/pypa/virtualenv@c21fef2c2d53cf19f49bcc37f9c058a33fb50499"
run_pip("install", req)
result = run_pip("install", "-U", req)
script.pip("install", req)
result = script.pip("install", "-U", req)
assert not "pypi.python.org" in result.stdout, result.stdout
......@@ -227,56 +227,59 @@ class TestUpgradeSetuptools(object):
"""
def prep_ve(self, version, distribute=False):
self.env = reset_env(pypi_cache=False)
pip_install_local('virtualenv==%s' %version)
args = ['virtualenv', self.env.scratch_path/'VE']
self.script = reset_env()
self.script.pip_install_local('virtualenv==%s' %version)
args = ['virtualenv', self.script.scratch_path/'VE']
if distribute:
args.insert(1, '--distribute')
self.env.run(*args)
self.ve_bin = self.env.scratch_path/'VE'/'bin'
self.env.run(self.ve_bin/'pip', 'uninstall', '-y', 'pip')
self.env.run(self.ve_bin/'python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True)
if version == "1.9.1" and not distribute:
# setuptools 0.6 didn't support PYTHONDONTWRITEBYTECODE
del self.script.environ["PYTHONDONTWRITEBYTECODE"]
self.script.run(*args)
self.ve_bin = self.script.scratch_path/'VE'/'bin'
self.script.run(self.ve_bin/'pip', 'uninstall', '-y', 'pip')
self.script.run(self.ve_bin/'python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True)
@pytest.mark.skipif("sys.version_info >= (3,0)")
def test_py2_from_setuptools_6_to_setuptools_7(self):
self.prep_ve('1.9.1')
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
assert "Found existing installation: setuptools 0.6c11" in result.stdout
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.8)" in result.stdout
def test_py2_py3_from_distribute_6_to_setuptools_7(self):
self.prep_ve('1.9.1', distribute=True)
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
assert "Found existing installation: distribute 0.6.34" in result.stdout
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.8)" in result.stdout
"distribute (0.7.3)" in result.stdout
def test_from_setuptools_7_to_setuptools_7(self):
self.prep_ve('1.10')
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
assert "Found existing installation: setuptools 0.9.7" in result.stdout
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.8)" in result.stdout
def test_from_setuptools_7_to_setuptools_7_using_wheel(self):
self.prep_ve('1.10')
result = self.env.run(self.ve_bin/'pip', 'install', '--use-wheel', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--use-wheel', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
assert "Found existing installation: setuptools 0.9.7" in result.stdout
assert 'setuptools-0.9.8.dist-info' in str(result.files_created) #only wheels use dist-info
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.8)" in result.stdout
def test_from_setuptools_7_to_setuptools_7_with_distribute_7_installed(self):
self.prep_ve('1.9.1', distribute=True)
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, 'setuptools==0.9.6')
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, 'setuptools==0.9.6')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.6)" in result.stdout
"distribute (0.7.3)" in result.stdout
result = self.env.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
result = self.script.run(self.ve_bin/'pip', 'install', '--no-index', '--find-links=%s' % find_links, '-U', 'setuptools')
assert "Found existing installation: setuptools 0.9.6" in result.stdout
result = self.env.run(self.ve_bin/'pip', 'list')
result = self.script.run(self.ve_bin/'pip', 'list')
"setuptools (0.9.8)" in result.stdout
"distribute (0.7.3)" in result.stdout
"""
tests specific to "--user" option
"""
import imp
import sys
import os
import textwrap
from os.path import abspath, join, curdir, isdir, isfile
import pytest
from pip.backwardcompat import uses_pycache
from tests.lib.local_repos import local_checkout
from tests.lib import (tests_data, reset_env, run_pip, pyversion, assert_all_changes,
path_to_url, find_links, pip_install_local)
from tests.lib import (tests_data, reset_env, pyversion, assert_all_changes,
find_links)
patch_dist_in_site_packages = """
def dist_in_site_packages(dist):
return False
from pip import req
req.dist_in_site_packages=dist_in_site_packages
"""
def _patch_dist_in_site_packages(script):
sitecustomize_path = script.lib_path.join("sitecustomize.py")
sitecustomize_path.write(textwrap.dedent("""
def dist_in_site_packages(dist):
return False
from pip import req
req.dist_in_site_packages = dist_in_site_packages
"""))
# Caught py32 with an outdated __pycache__ file after a sitecustomize
# update (after python should have updated it) so will delete the cache
# file to be sure
# See: https://github.com/pypa/pip/pull/893#issuecomment-16426701
if uses_pycache:
cache_path = imp.cache_from_source(sitecustomize_path)
if os.path.isfile(cache_path):
os.remove(cache_path)
# --user option is broken in pypy
......@@ -29,9 +46,9 @@ class Tests_UserSite:
"""
reset_env(system_site_packages=True) produces env where a --user install can be found using pkg_resources
"""
env = reset_env(system_site_packages=True)
run_pip('install', '--user', 'INITools==0.2')
result = env.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').project_name)")
script = reset_env(system_site_packages=True)
script.pip('install', '--user', 'INITools==0.2')
result = script.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').project_name)")
project_name = result.stdout.strip()
assert 'INITools'== project_name, "'%s' should be 'INITools'" %project_name
......@@ -40,8 +57,8 @@ class Tests_UserSite:
"""
Test installing current directory ('.') into usersite after installing distribute
"""
env = reset_env(system_site_packages=True)
result = run_pip('install', '--user', '-e',
script = reset_env(system_site_packages=True)
result = script.pip('install', '--user', '-e',
'%s#egg=initools-dev' %
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
result.assert_installed('INITools', use_user_site=True)
......@@ -51,11 +68,11 @@ class Tests_UserSite:
"""
Test installing current directory ('.') into usersite
"""
env = reset_env(system_site_packages=True)
script = reset_env(system_site_packages=True)
run_from = abspath(join(tests_data, 'packages', 'FSPkg'))
result = run_pip('install', '--user', curdir, cwd=run_from, expect_error=False)
fspkg_folder = env.user_site/'fspkg'
egg_info_folder = env.user_site/'FSPkg-0.1dev-py%s.egg-info' % pyversion
result = script.pip('install', '--user', curdir, cwd=run_from, expect_error=False)
fspkg_folder = script.user_site/'fspkg'
egg_info_folder = script.user_site/'FSPkg-0.1dev-py%s.egg-info' % pyversion
assert fspkg_folder in result.files_created, str(result.stdout)
assert egg_info_folder in result.files_created, str(result)
......@@ -65,9 +82,9 @@ class Tests_UserSite:
"""
user install in virtualenv (with no system packages) fails with message
"""
env = reset_env()
script = reset_env()
run_from = abspath(join(tests_data, 'packages', 'FSPkg'))
result = run_pip('install', '--user', curdir, cwd=run_from, expect_error=True)
result = script.pip('install', '--user', curdir, cwd=run_from, expect_error=True)
assert "Can not perform a '--user' install. User site-packages are not visible in this virtualenv." in result.stdout
......@@ -76,13 +93,13 @@ class Tests_UserSite:
Test user install with conflict in usersite updates usersite.
"""
env = reset_env(system_site_packages=True)
result1 = run_pip('install', '--user', 'INITools==0.3')
result2 = run_pip('install', '--user', 'INITools==0.1')
script = reset_env(system_site_packages=True)
result1 = script.pip('install', '--user', 'INITools==0.3')
result2 = script.pip('install', '--user', 'INITools==0.1')
#usersite has 0.1
egg_info_folder = env.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_v3_file = env.root_path / env.user_site / 'initools' / 'configparser.py' #file only in 0.3
egg_info_folder = script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_v3_file = script.base_path / script.user_site / 'initools' / 'configparser.py' #file only in 0.3
assert egg_info_folder in result2.files_created, str(result2)
assert not isfile(initools_v3_file), initools_v3_file
......@@ -99,21 +116,22 @@ class Tests_UserSite:
# 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
script = reset_env(system_site_packages=True)
script.environ["PYTHONPATH"] = script.base_path / script.user_site
_patch_dist_in_site_packages(script)
result1 = run_pip('install', 'INITools==0.2')
result2 = run_pip('install', '--user', 'INITools==0.1')
result1 = script.pip('install', 'INITools==0.2')
result2 = script.pip('install', '--user', 'INITools==0.1')
#usersite has 0.1
egg_info_folder = env.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_folder = env.user_site / 'initools'
egg_info_folder = script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_folder = script.user_site / 'initools'
assert egg_info_folder in result2.files_created, str(result2)
assert initools_folder in result2.files_created, str(result2)
#site still has 0.2 (can't look in result1; have to check)
egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = env.root_path / env.site_packages / 'initools'
egg_info_folder = script.base_path / script.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = script.base_path / script.site_packages / 'initools'
assert isdir(egg_info_folder)
assert isdir(initools_folder)
......@@ -130,21 +148,22 @@ class Tests_UserSite:
# 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
script = reset_env(system_site_packages=True)
script.environ["PYTHONPATH"] = script.base_path / script.user_site
_patch_dist_in_site_packages(script)
result1 = run_pip('install', 'INITools==0.2')
result2 = run_pip('install', '--user', '--upgrade', 'INITools')
result1 = script.pip('install', 'INITools==0.2')
result2 = script.pip('install', '--user', '--upgrade', 'INITools')
#usersite has 0.3.1
egg_info_folder = env.user_site / 'INITools-0.3.1-py%s.egg-info' % pyversion
initools_folder = env.user_site / 'initools'
egg_info_folder = script.user_site / 'INITools-0.3.1-py%s.egg-info' % pyversion
initools_folder = script.user_site / 'initools'
assert egg_info_folder in result2.files_created, str(result2)
assert initools_folder in result2.files_created, str(result2)
#site still has 0.2 (can't look in result1; have to check)
egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = env.root_path / env.site_packages / 'initools'
egg_info_folder = script.base_path / script.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = script.base_path / script.site_packages / 'initools'
assert isdir(egg_info_folder), result2.stdout
assert isdir(initools_folder)
......@@ -161,22 +180,23 @@ class Tests_UserSite:
# 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
script = reset_env(system_site_packages=True)
script.environ["PYTHONPATH"] = script.base_path / script.user_site
_patch_dist_in_site_packages(script)
result1 = run_pip('install', 'INITools==0.2')
result2 = run_pip('install', '--user', 'INITools==0.3')
result3 = run_pip('install', '--user', 'INITools==0.1')
result1 = script.pip('install', 'INITools==0.2')
result2 = script.pip('install', '--user', 'INITools==0.3')
result3 = script.pip('install', '--user', 'INITools==0.1')
#usersite has 0.1
egg_info_folder = env.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_v3_file = env.root_path / env.user_site / 'initools' / 'configparser.py' #file only in 0.3
egg_info_folder = script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion
initools_v3_file = script.base_path / script.user_site / 'initools' / 'configparser.py' #file only in 0.3
assert egg_info_folder in result3.files_created, str(result3)
assert not isfile(initools_v3_file), initools_v3_file
#site still has 0.2 (can't just look in result1; have to check)
egg_info_folder = env.root_path / env.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = env.root_path / env.site_packages / 'initools'
egg_info_folder = script.base_path / script.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion
initools_folder = script.base_path / script.site_packages / 'initools'
assert isdir(egg_info_folder)
assert isdir(initools_folder)
......@@ -185,10 +205,10 @@ class Tests_UserSite:
"""
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)")
script = reset_env(system_site_packages=True)
result1 = script.pip('install', 'INITools==0.2')
result2 = script.pip('install', '--user', 'INITools==0.1', expect_error=True)
resultp = script.run('python', '-c', "import pkg_resources; print(pkg_resources.get_distribution('initools').location)")
dist_location = resultp.stdout.strip()
assert "Will not install to the user site because it will lack sys.path precedence to %s in %s" \
% ('INITools', dist_location) in result2.stdout, result2.stdout
......@@ -198,41 +218,40 @@ class Tests_UserSite:
"""
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'])
script = reset_env(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'])
def test_uninstall_editable_from_usersite(self):
"""
Test uninstall editable local user install
"""
env = reset_env(system_site_packages=True)
script = reset_env(system_site_packages=True)
script.user_site_path.makedirs()
#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'
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 = run_pip('uninstall', '-y', 'FSPkg')
assert not isfile(env.root_path / egg_link)
result2 = script.pip('uninstall', '-y', 'FSPkg')
assert not isfile(script.base_path / egg_link)
assert_all_changes(result1, result2,
[env.venv/'build', 'cache', env.user_site/'easy-install.pth'])
[script.venv/'build', 'cache', script.user_site/'easy-install.pth'])
def test_install_user_wheel(self):
"""
Test user install from wheel
"""
env = reset_env(system_site_packages=True)
pip_install_local('wheel')
result = run_pip('install', 'simple.dist==0.1', '--user', '--use-wheel',
script = reset_env(system_site_packages=True)
script.pip_install_local('wheel')
result = script.pip('install', 'simple.dist==0.1', '--user', '--use-wheel',
'--no-index', '--find-links='+find_links)
egg_info_folder = env.user_site / 'simple.dist-0.1.dist-info'
egg_info_folder = script.user_site / 'simple.dist-0.1.dist-info'
assert egg_info_folder in result.files_created, str(result)
from tests.lib import (reset_env, run_pip,
from tests.lib import (reset_env,
_create_test_package, _change_test_package_version)
from tests.lib.local_repos import local_checkout
......@@ -7,8 +7,8 @@ def test_install_editable_from_git_with_https():
"""
Test cloning from Git with https.
"""
reset_env()
result = run_pip('install', '-e',
script = reset_env()
result = script.pip('install', '-e',
'%s#egg=pip-test-package' %
local_checkout('git+https://github.com/pypa/pip-test-package.git'),
expect_error=True)
......@@ -19,12 +19,12 @@ def test_git_with_sha1_revisions():
"""
Git backend should be able to install from SHA1 revisions
"""
env = reset_env()
version_pkg_path = _create_test_package(env)
_change_test_package_version(env, version_pkg_path)
sha1 = env.run('git', 'rev-parse', 'HEAD~1', cwd=version_pkg_path).stdout.strip()
run_pip('install', '-e', '%s@%s#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/'), sha1))
version = env.run('version_pkg')
script = reset_env()
version_pkg_path = _create_test_package(script)
_change_test_package_version(script, version_pkg_path)
sha1 = script.run('git', 'rev-parse', 'HEAD~1', cwd=version_pkg_path).stdout.strip()
script.pip('install', '-e', '%s@%s#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/'), sha1))
version = script.run('version_pkg')
assert '0.1' in version.stdout, version.stdout
......@@ -32,12 +32,12 @@ def test_git_with_branch_name_as_revision():
"""
Git backend should be able to install from branch names
"""
env = reset_env()
version_pkg_path = _create_test_package(env)
env.run('git', 'checkout', '-b', 'test_branch', expect_stderr=True, cwd=version_pkg_path)
_change_test_package_version(env, version_pkg_path)
run_pip('install', '-e', '%s@test_branch#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/')))
version = env.run('version_pkg')
script = reset_env()
version_pkg_path = _create_test_package(script)
script.run('git', 'checkout', '-b', 'test_branch', expect_stderr=True, cwd=version_pkg_path)
_change_test_package_version(script, version_pkg_path)
script.pip('install', '-e', '%s@test_branch#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/')))
version = script.run('version_pkg')
assert 'some different version' in version.stdout
......@@ -45,12 +45,12 @@ def test_git_with_tag_name_as_revision():
"""
Git backend should be able to install from tag names
"""
env = reset_env()
version_pkg_path = _create_test_package(env)
env.run('git', 'tag', 'test_tag', expect_stderr=True, cwd=version_pkg_path)
_change_test_package_version(env, version_pkg_path)
run_pip('install', '-e', '%s@test_tag#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/')))
version = env.run('version_pkg')
script = reset_env()
version_pkg_path = _create_test_package(script)
script.run('git', 'tag', 'test_tag', expect_stderr=True, cwd=version_pkg_path)
_change_test_package_version(script, version_pkg_path)
script.pip('install', '-e', '%s@test_tag#egg=version_pkg' % ('git+file://' + version_pkg_path.abspath.replace('\\', '/')))
version = script.run('version_pkg')
assert '0.1' in version.stdout
......@@ -58,12 +58,12 @@ def test_git_with_tag_name_and_update():
"""
Test cloning a git repository and updating to a different version.
"""
reset_env()
result = run_pip('install', '-e', '%s#egg=pip-test-package' %
script = reset_env()
result = script.pip('install', '-e', '%s#egg=pip-test-package' %
local_checkout('git+http://github.com/pypa/pip-test-package.git'),
expect_error=True)
result.assert_installed('pip-test-package', with_files=['.git'])
result = run_pip('install', '--global-option=--version', '-e',
result = script.pip('install', '--global-option=--version', '-e',
'%s@0.1.2#egg=pip-test-package' %
local_checkout('git+http://github.com/pypa/pip-test-package.git'),
expect_error=True)
......@@ -75,12 +75,12 @@ def test_git_branch_should_not_be_changed():
Editable installations should not change branch
related to issue #32 and #161
"""
env = reset_env()
run_pip('install', '-e', '%s#egg=pip-test-package' %
script = reset_env()
script.pip('install', '-e', '%s#egg=pip-test-package' %
local_checkout('git+http://github.com/pypa/pip-test-package.git'),
expect_error=True)
source_dir = env.venv_path/'src'/'pip-test-package'
result = env.run('git', 'branch', cwd=source_dir)
source_dir = script.venv_path/'src'/'pip-test-package'
result = script.run('git', 'branch', cwd=source_dir)
assert '* master' in result.stdout, result.stdout
......@@ -88,8 +88,8 @@ def test_git_with_non_editable_unpacking():
"""
Test cloning a git repository from a non-editable URL with a given tag.
"""
reset_env()
result = run_pip('install', '--global-option=--version', local_checkout(
script = reset_env()
result = script.pip('install', '--global-option=--version', local_checkout(
'git+http://github.com/pypa/pip-test-package.git@0.1.2#egg=pip-test-package'
), expect_error=True)
assert '0.1.2' in result.stdout
......@@ -99,8 +99,8 @@ def test_git_with_editable_where_egg_contains_dev_string():
"""
Test cloning a git repository from an editable url which contains "dev" string
"""
reset_env()
result = run_pip('install', '-e', '%s#egg=django-devserver' %
script = reset_env()
result = script.pip('install', '-e', '%s#egg=django-devserver' %
local_checkout('git+git://github.com/dcramer/django-devserver.git'))
result.assert_installed('django-devserver', with_files=['.git'])
......@@ -109,10 +109,10 @@ def test_git_with_non_editable_where_egg_contains_dev_string():
"""
Test cloning a git repository from a non-editable url which contains "dev" string
"""
env = reset_env()
result = run_pip('install', '%s#egg=django-devserver' %
script = reset_env()
result = script.pip('install', '%s#egg=django-devserver' %
local_checkout('git+git://github.com/dcramer/django-devserver.git'))
devserver_folder = env.site_packages/'devserver'
devserver_folder = script.site_packages/'devserver'
assert devserver_folder in result.files_created, str(result)
......@@ -120,11 +120,11 @@ def test_git_with_ambiguous_revs():
"""
Test git with two "names" (tag/branch) pointing to the same commit
"""
env = reset_env()
version_pkg_path = _create_test_package(env)
script = reset_env()
version_pkg_path = _create_test_package(script)
package_url = 'git+file://%s@0.1#egg=version_pkg' % (version_pkg_path.abspath.replace('\\', '/'))
env.run('git', 'tag', '0.1', cwd=version_pkg_path)
result = run_pip('install', '-e', package_url)
script.run('git', 'tag', '0.1', cwd=version_pkg_path)
result = script.pip('install', '-e', package_url)
assert 'Could not find a tag or branch' not in result.stdout
# it is 'version-pkg' instead of 'version_pkg' because
# egg-link name is version-pkg.egg-link because it is a single .py module
......@@ -133,14 +133,12 @@ def test_git_with_ambiguous_revs():
def test_git_works_with_editable_non_origin_repo():
# set up, create a git repo and install it as editable from a local directory path
env = reset_env()
version_pkg_path = _create_test_package(env)
run_pip('install', '-e', version_pkg_path.abspath)
script = reset_env()
version_pkg_path = _create_test_package(script)
script.pip('install', '-e', version_pkg_path.abspath)
# 'freeze'ing this should not fall over, but should result in stderr output warning
result = run_pip('freeze', expect_stderr=True)
result = script.pip('freeze', expect_stderr=True)
assert "Error when trying to get requirement" in result.stderr
assert "Could not determine repository location" in result.stdout
assert "version-pkg==0.1" in result.stdout
......@@ -5,8 +5,7 @@ import pytest
from mock import patch
from pip.vcs.git import Git
from tests.lib import (reset_env, run_pip,
_create_test_package,)
from tests.lib import reset_env, _create_test_package
from tests.lib.git_submodule_helpers import (
_change_test_package_submodule,
_pull_in_submodule_changes_to_module,
......@@ -15,11 +14,11 @@ from tests.lib.git_submodule_helpers import (
def test_get_refs_should_return_tag_name_and_commit_pair():
env = reset_env()
version_pkg_path = _create_test_package(env)
env.run('git', 'tag', '0.1', cwd=version_pkg_path)
env.run('git', 'tag', '0.2', cwd=version_pkg_path)
commit = env.run('git', 'rev-parse', 'HEAD',
script = reset_env()
version_pkg_path = _create_test_package(script)
script.run('git', 'tag', '0.1', cwd=version_pkg_path)
script.run('git', 'tag', '0.2', cwd=version_pkg_path)
commit = script.run('git', 'rev-parse', 'HEAD',
cwd=version_pkg_path).stdout.strip()
git = Git()
result = git.get_refs(version_pkg_path)
......@@ -28,10 +27,10 @@ def test_get_refs_should_return_tag_name_and_commit_pair():
def test_get_refs_should_return_branch_name_and_commit_pair():
env = reset_env()
version_pkg_path = _create_test_package(env)
env.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = env.run('git', 'rev-parse', 'HEAD',
script = reset_env()
version_pkg_path = _create_test_package(script)
script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = script.run('git', 'rev-parse', 'HEAD',
cwd=version_pkg_path).stdout.strip()
git = Git()
result = git.get_refs(version_pkg_path)
......@@ -40,13 +39,13 @@ def test_get_refs_should_return_branch_name_and_commit_pair():
def test_get_refs_should_ignore_no_branch():
env = reset_env()
version_pkg_path = _create_test_package(env)
env.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = env.run('git', 'rev-parse', 'HEAD',
script = reset_env()
version_pkg_path = _create_test_package(script)
script.run('git', 'branch', 'branch0.1', cwd=version_pkg_path)
commit = script.run('git', 'rev-parse', 'HEAD',
cwd=version_pkg_path).stdout.strip()
# current branch here is "* (nobranch)"
env.run('git', 'checkout', commit,
script.run('git', 'checkout', commit,
cwd=version_pkg_path, expect_stderr=True)
git = Git()
result = git.get_refs(version_pkg_path)
......@@ -88,17 +87,16 @@ def test_check_submodule_addition():
Submodules are pulled in on install and updated on upgrade.
"""
env = reset_env()
module_path, submodule_path = _create_test_package_with_submodule(env)
script = reset_env()
module_path, submodule_path = _create_test_package_with_submodule(script)
install_result = run_pip('install', '-e', 'git+'+module_path+'#egg=version_pkg')
install_result = script.pip('install', '-e', 'git+'+module_path+'#egg=version_pkg')
assert '.virtualenv/src/version-pkg/testpkg/static/testfile' in install_result.files_created
_change_test_package_submodule(env, submodule_path)
_pull_in_submodule_changes_to_module(env, module_path)
_change_test_package_submodule(script, submodule_path)
_pull_in_submodule_changes_to_module(script, module_path)
# expect error because git may write to stderr
update_result = run_pip('install', '-e', 'git+'+module_path+'#egg=version_pkg', '--upgrade', expect_error=True)
assert env.venv/'src/version-pkg/testpkg/static/testfile2' in update_result.files_created
update_result = script.pip('install', '-e', 'git+'+module_path+'#egg=version_pkg', '--upgrade', expect_error=True)
assert script.venv/'src/version-pkg/testpkg/static/testfile2' in update_result.files_created
from os.path import abspath, join
from tests.lib import tests_data, reset_env, run_pip, pip_install_local, find_links
from tests.lib import tests_data, reset_env, find_links
from tests.lib.path import Path
......@@ -8,11 +8,11 @@ def test_install_from_wheel():
"""
Test installing from a wheel.
"""
env = reset_env()
result = run_pip('install', 'simple.dist', '--use-wheel',
script = reset_env()
result = script.pip('install', 'simple.dist', '--use-wheel',
'--no-index', '--find-links='+find_links,
expect_error=False)
dist_info_folder = env.site_packages/'simple.dist-0.1.dist-info'
dist_info_folder = script.site_packages/'simple.dist-0.1.dist-info'
assert dist_info_folder in result.files_created, (dist_info_folder,
result.files_created,
result.stdout)
......@@ -22,15 +22,15 @@ def test_install_from_wheel_with_extras():
"""
Test installing from a wheel with extras.
"""
env = reset_env()
result = run_pip('install', 'complex-dist[simple]', '--use-wheel',
script = reset_env()
result = script.pip('install', 'complex-dist[simple]', '--use-wheel',
'--no-index', '--find-links='+find_links,
expect_error=False)
dist_info_folder = env.site_packages/'complex_dist-0.1.dist-info'
dist_info_folder = script.site_packages/'complex_dist-0.1.dist-info'
assert dist_info_folder in result.files_created, (dist_info_folder,
result.files_created,
result.stdout)
dist_info_folder = env.site_packages/'simple.dist-0.1.dist-info'
dist_info_folder = script.site_packages/'simple.dist-0.1.dist-info'
assert dist_info_folder in result.files_created, (dist_info_folder,
result.files_created,
result.stdout)
......@@ -40,12 +40,12 @@ def test_install_from_wheel_file():
"""
Test installing directly from a wheel file.
"""
env = reset_env()
script = reset_env()
package = abspath(join(tests_data,
'packages',
'headers.dist-0.1-py2.py3-none-any.whl'))
result = run_pip('install', package, '--no-index', expect_error=False)
dist_info_folder = env.site_packages/'headers.dist-0.1.dist-info'
result = script.pip('install', package, '--no-index', expect_error=False)
dist_info_folder = script.site_packages/'headers.dist-0.1.dist-info'
assert dist_info_folder in result.files_created, (dist_info_folder,
result.files_created,
result.stdout)
......@@ -55,10 +55,10 @@ def test_install_wheel_with_target():
"""
Test installing a wheel using pip install --target
"""
env = reset_env()
pip_install_local('wheel')
target_dir = env.scratch_path/'target'
result = run_pip('install', 'simple.dist==0.1', '-t', target_dir, '--use-wheel',
script = reset_env()
script.pip_install_local('wheel')
target_dir = script.scratch_path/'target'
result = script.pip('install', 'simple.dist==0.1', '-t', target_dir, '--use-wheel',
'--no-index', '--find-links='+find_links)
assert Path('scratch')/'target'/'simpledist' in result.files_created, str(result)
......@@ -68,11 +68,11 @@ def test_install_from_wheel_installs_deps():
Test can install dependencies of wheels
"""
# 'requires_source' depends on the 'source' project
env = reset_env()
script = reset_env()
package = abspath(join(tests_data,
'packages',
'requires_source-1.0-py2.py3-none-any.whl'))
result = run_pip('install', '--no-index', '--find-links', find_links, package)
result = script.pip('install', '--no-index', '--find-links', find_links, package)
result.assert_installed('source', editable=False)
......@@ -81,13 +81,10 @@ def test_install_from_wheel_no_deps():
Test --no-deps works with wheel installs
"""
# 'requires_source' depends on the 'source' project
env = reset_env()
script = reset_env()
package = abspath(join(tests_data,
'packages',
'requires_source-1.0-py2.py3-none-any.whl'))
result = run_pip('install', '--no-index', '--find-links', find_links, '--no-deps', package)
pkg_folder = env.site_packages/'source'
result = script.pip('install', '--no-index', '--find-links', find_links, '--no-deps', package)
pkg_folder = script.site_packages/'source'
assert pkg_folder not in result.files_created
import os
import re
import textwrap
from tests.lib import (pyversion, reset_env, run_pip, write_file, path_to_url,
tests_data, find_links)
from tests.lib import pyversion, reset_env, path_to_url, tests_data, find_links
from tests.lib.local_repos import local_checkout
......@@ -11,9 +10,9 @@ def test_list_command():
Test default behavior of list command.
"""
reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
result = run_pip('list')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
result = script.pip('list')
assert 'simple (1.0)' in result.stdout, str(result)
assert 'simple2 (3.0)' in result.stdout, str(result)
......@@ -23,9 +22,9 @@ def test_local_flag():
Test the behavior of --local flag in the list command
"""
reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple==1.0')
result = run_pip('list', '--local')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple==1.0')
result = script.pip('list', '--local')
assert 'simple (1.0)' in result.stdout
......@@ -34,10 +33,10 @@ def test_uptodate_flag():
Test the behavior of --uptodate flag in the list command
"""
reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
run_pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = run_pip('list', '-f', find_links, '--no-index', '--uptodate')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
script.pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = script.pip('list', '-f', find_links, '--no-index', '--uptodate')
assert 'simple (1.0)' not in result.stdout #3.0 is latest
assert 'pip-test-package' not in result.stdout #editables excluded
assert 'simple2 (3.0)' in result.stdout, str(result)
......@@ -48,10 +47,10 @@ def test_outdated_flag():
Test the behavior of --outdated flag in the list command
"""
reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
run_pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = run_pip('list', '-f', find_links, '--no-index', '--outdated')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple==1.0', 'simple2==3.0')
script.pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = script.pip('list', '-f', find_links, '--no-index', '--outdated')
assert 'simple (Current: 1.0 Latest: 3.0)' in result.stdout
assert 'pip-test-package' not in result.stdout #editables excluded
assert 'simple2' not in result.stdout, str(result) #3.0 is latest
......@@ -61,10 +60,9 @@ def test_editables_flag():
"""
Test the behavior of --editables flag in the list command
"""
reset_env()
run_pip('install', '-f', find_links, '--no-index', 'simple==1.0')
result = run_pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = run_pip('list', '--editable')
script = reset_env()
script.pip('install', '-f', find_links, '--no-index', 'simple==1.0')
result = script.pip('install', '-e', 'git+https://github.com/pypa/pip-test-package.git#egg=pip-test-package')
result = script.pip('list', '--editable')
assert 'simple (1.0)' not in result.stdout, str(result)
assert os.path.join('src', 'pip-test-package') in result.stdout, str(result)
......@@ -7,8 +7,7 @@ from pip.status_codes import NO_MATCHES_FOUND, SUCCESS
from pip.backwardcompat import xmlrpclib, b
from pip.baseparser import create_main_parser
from mock import Mock
from tests.lib import run_pip, reset_env, pyversion
from tests.lib.pypi_server import assert_equal
from tests.lib import reset_env, pyversion
if pyversion >= '3':
......@@ -40,7 +39,7 @@ def test_pypi_xml_transformation():
{'_pypi_ordering': 50, 'name': 'bar', 'summary': 'bar summary', 'version': '1.0'}]
expected = [{'score': 200, 'versions': ['1.0', '2.0'], 'name': 'foo', 'summary': 'foo summary v2'},
{'score': 50, 'versions': ['1.0'], 'name': 'bar', 'summary': 'bar summary'}]
assert_equal(transform_hits(pypi_hits), expected)
assert transform_hits(pypi_hits) == expected
def test_invalid_pypi_transformation():
......@@ -52,7 +51,7 @@ def test_invalid_pypi_transformation():
expected = [{'score': 100, 'versions': ['1.0'], 'name': 'foo', 'summary': 'foo summary'},
{'score': 0, 'versions': ['1.0'], 'name': 'bar', 'summary': 'bar summary'}]
assert_equal(transform_hits(pypi_hits), expected)
assert transform_hits(pypi_hits) == expected
def test_search():
......@@ -60,8 +59,8 @@ def test_search():
End to end test of search command.
"""
reset_env()
output = run_pip('search', 'pip')
script = reset_env()
output = script.pip('search', 'pip')
assert 'A tool for installing and managing Python packages' in output.stdout
......@@ -70,8 +69,8 @@ def test_multiple_search():
Test searching for multiple packages at once.
"""
reset_env()
output = run_pip('search', 'pip', 'INITools')
script = reset_env()
output = script.pip('search', 'pip', 'INITools')
assert 'A tool for installing and managing Python packages' in output.stdout
assert 'Tools for parsing and using INI-style files' in output.stdout
......@@ -80,8 +79,8 @@ def test_search_missing_argument():
"""
Test missing required argument for search
"""
env = reset_env()
result = run_pip('search', expect_error=True)
script = reset_env()
result = script.pip('search', expect_error=True)
assert 'ERROR: Missing required argument (search query).' in result.stdout
......@@ -111,8 +110,8 @@ def test_search_should_exit_status_code_zero_when_find_packages():
"""
Test search exit status code for package found
"""
env = reset_env()
result = run_pip('search', 'pip')
script = reset_env()
result = script.pip('search', 'pip')
assert result.returncode == SUCCESS
......@@ -120,6 +119,6 @@ def test_search_exit_status_code_when_finds_no_package():
"""
Test search exit status code for no matches
"""
env = reset_env()
result = run_pip('search', 'non-existant-package', expect_error=True)
script = reset_env()
result = script.pip('search', 'non-existant-package', expect_error=True)
assert result.returncode == NO_MATCHES_FOUND, result.returncode
import re
from pip import __version__
from pip.commands.show import search_packages_info
from tests.lib import reset_env, run_pip
from tests.lib import reset_env
def test_show():
......@@ -9,8 +9,8 @@ def test_show():
Test end to end test for show command.
"""
reset_env()
result = run_pip('show', 'pip')
script = reset_env()
result = script.pip('show', 'pip')
lines = result.stdout.split('\n')
assert len(lines) == 6
assert lines[0] == '---', lines[0]
......@@ -26,8 +26,8 @@ def test_show_with_files_not_found():
installed-files.txt not found.
"""
reset_env()
result = run_pip('show', '-f', 'pip')
script = reset_env()
result = script.pip('show', '-f', 'pip')
lines = result.stdout.split('\n')
assert len(lines) == 8
assert lines[0] == '---', lines[0]
......@@ -44,9 +44,9 @@ def test_show_with_all_files():
Test listing all files in the show command.
"""
reset_env()
result = run_pip('install', 'initools==0.2')
result = run_pip('show', '--files', 'initools')
script = reset_env()
result = script.pip('install', 'initools==0.2')
result = script.pip('show', '--files', 'initools')
assert re.search(r"Files:\n( .+\n)+", result.stdout)
......@@ -55,8 +55,8 @@ def test_missing_argument():
Test show command with no arguments.
"""
reset_env()
result = run_pip('show')
script = reset_env()
result = script.pip('show')
assert 'ERROR: Please provide a package name or names.' in result.stdout
......
......@@ -6,7 +6,7 @@ import sys
from os.path import join, abspath, normpath
from tempfile import mkdtemp
from mock import patch
from tests.lib import tests_data, reset_env, run_pip, assert_all_changes, write_file, pyversion
from tests.lib import tests_data, reset_env, assert_all_changes, pyversion
from tests.lib.local_repos import local_repo, local_checkout
from pip.util import rmtree
......@@ -17,13 +17,13 @@ def test_simple_uninstall():
Test simple install and uninstall.
"""
env = reset_env()
result = run_pip('install', 'INITools==0.2')
assert join(env.site_packages, 'initools') in result.files_created, sorted(result.files_created.keys())
script = reset_env()
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
env.run('python', '-c', "import initools")
result2 = run_pip('uninstall', 'INITools', '-y')
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
script.run('python', '-c', "import initools")
result2 = script.pip('uninstall', 'INITools', '-y')
assert_all_changes(result, result2, [script.venv/'build', 'cache'])
def test_uninstall_with_scripts():
......@@ -31,13 +31,13 @@ def test_uninstall_with_scripts():
Uninstall an easy_installed package with scripts.
"""
env = reset_env()
result = env.run('easy_install', 'PyLogo', expect_stderr=True)
easy_install_pth = env.site_packages/ 'easy-install.pth'
script = reset_env()
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 = run_pip('uninstall', 'pylogo', '-y', expect_error=True)
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
result2 = script.pip('uninstall', 'pylogo', '-y', expect_error=True)
assert_all_changes(result, result2, [script.venv/'build', 'cache'])
def test_uninstall_easy_install_after_import():
......@@ -45,12 +45,12 @@ 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)
script = reset_env()
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
env.run('python', '-c', "import initools")
result2 = run_pip('uninstall', 'INITools', '-y')
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
script.run('python', '-c', "import initools")
result2 = script.pip('uninstall', 'INITools', '-y')
assert_all_changes(result, result2, [script.venv/'build', 'cache'])
def test_uninstall_namespace_package():
......@@ -59,12 +59,12 @@ def test_uninstall_namespace_package():
the namespace and everything in it.
"""
env = reset_env()
result = run_pip('install', 'pd.requires==0.0.3', expect_error=True)
assert join(env.site_packages, 'pd') in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('uninstall', 'pd.find', '-y', expect_error=True)
assert join(env.site_packages, 'pd') not in result2.files_deleted, sorted(result2.files_deleted.keys())
assert join(env.site_packages, 'pd', 'find') in result2.files_deleted, sorted(result2.files_deleted.keys())
script = reset_env()
result = script.pip('install', 'pd.requires==0.0.3', expect_error=True)
assert join(script.site_packages, 'pd') in result.files_created, sorted(result.files_created.keys())
result2 = script.pip('uninstall', 'pd.find', '-y', expect_error=True)
assert join(script.site_packages, 'pd') not in result2.files_deleted, sorted(result2.files_deleted.keys())
assert join(script.site_packages, 'pd', 'find') in result2.files_deleted, sorted(result2.files_deleted.keys())
def test_uninstall_overlapping_package():
......@@ -77,18 +77,18 @@ def test_uninstall_overlapping_package():
"""
parent_pkg = abspath(join(tests_data, 'packages', 'parent-0.1.tar.gz'))
child_pkg = abspath(join(tests_data, 'packages', 'child-0.1.tar.gz'))
env = reset_env()
result1 = run_pip('install', parent_pkg, expect_error=False)
assert join(env.site_packages, 'parent') in result1.files_created, sorted(result1.files_created.keys())
result2 = run_pip('install', child_pkg, expect_error=False)
assert join(env.site_packages, 'child') in result2.files_created, sorted(result2.files_created.keys())
assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result2.files_created, sorted(result2.files_created.keys())
script = reset_env()
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
env.run('python', '-c', "import parent.plugins.child_plugin, child")
result3 = run_pip('uninstall', '-y', 'child', expect_error=False)
assert join(env.site_packages, 'child') in result3.files_deleted, sorted(result3.files_created.keys())
assert normpath(join(env.site_packages, 'parent/plugins/child_plugin.py')) in result3.files_deleted, sorted(result3.files_deleted.keys())
assert join(env.site_packages, 'parent') not in result3.files_deleted, sorted(result3.files_deleted.keys())
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, [])
......@@ -99,13 +99,13 @@ def test_uninstall_console_scripts():
Test uninstalling a package with more files (console_script entry points, extra directories).
"""
env = reset_env()
script = reset_env()
args = ['install']
args.append('discover')
result = run_pip(*args, **{"expect_error": True})
assert env.bin/'discover'+env.exe in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('uninstall', 'discover', '-y', expect_error=True)
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
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'])
def test_uninstall_easy_installed_console_scripts():
......@@ -113,13 +113,13 @@ def test_uninstall_easy_installed_console_scripts():
Test uninstalling package with console_scripts that is easy_installed.
"""
env = reset_env()
script = 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'])
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'])
def test_uninstall_editable_from_svn():
......@@ -127,13 +127,13 @@ 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' %
script = reset_env()
result = script.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'])
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'])
def test_uninstall_editable_with_source_outside_venv():
......@@ -150,12 +150,12 @@ def test_uninstall_editable_with_source_outside_venv():
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'])
script = reset_env()
result = script.run('git', 'clone', local_repo('git+git://github.com/pypa/virtualenv'), tmpdir)
result2 = script.pip('install', '-e', tmpdir)
assert (join(script.site_packages, 'virtualenv.egg-link') in result2.files_created), list(result2.files_created.keys())
result3 = script.pip('uninstall', '-y', 'virtualenv', expect_error=True)
assert_all_changes(result, result3, [script.venv/'build'])
def test_uninstall_from_reqs_file():
......@@ -163,14 +163,14 @@ def test_uninstall_from_reqs_file():
Test uninstall from a requirements file.
"""
env = reset_env()
write_file('test-req.txt', textwrap.dedent("""\
script = reset_env()
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')))
result = run_pip('install', '-r', 'test-req.txt')
write_file('test-req.txt', textwrap.dedent("""\
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
......@@ -180,9 +180,9 @@ def test_uninstall_from_reqs_file():
# 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')
result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y')
assert_all_changes(
result, result2, [env.venv/'build', env.venv/'src', env.scratch/'test-req.txt'])
result, result2, [script.venv/'build', script.venv/'src', script.scratch/'test-req.txt'])
def test_uninstall_as_egg():
......@@ -190,16 +190,16 @@ def test_uninstall_as_egg():
Test uninstall package installed as egg.
"""
env = reset_env()
script = reset_env()
to_install = abspath(join(tests_data, 'packages', 'FSPkg'))
result = run_pip('install', to_install, '--egg', expect_error=False)
fspkg_folder = env.site_packages/'fspkg'
egg_folder = env.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
result = script.pip('install', to_install, '--egg', expect_error=False)
fspkg_folder = script.site_packages/'fspkg'
egg_folder = script.site_packages/'FSPkg-0.1dev-py%s.egg' % pyversion
assert fspkg_folder not in result.files_created, str(result.stdout)
assert egg_folder in result.files_created, str(result)
result2 = run_pip('uninstall', 'FSPkg', '-y', expect_error=True)
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
result2 = script.pip('uninstall', 'FSPkg', '-y', expect_error=True)
assert_all_changes(result, result2, [script.venv/'build', 'cache'])
@patch('pip.req.logger')
......@@ -238,6 +238,3 @@ def test_uninstallpathset_non_local(mock_logger):
uninstall_set = UninstallPathSet(test_dist)
uninstall_set.remove() #with no files added to set; which is the case when trying to remove non-local dists
mock_logger.notify.assert_any_call("Not uninstalling pip at %s, outside environment %s" % (nonlocal_path, sys.prefix)), mock_logger.notify.mock_calls
......@@ -7,26 +7,26 @@ from os.path import exists
from pip import wheel
from pip.download import path_to_url as path_to_url_d
from tests.lib import tests_data, reset_env, run_pip, pyversion_nodot, write_file, path_to_url, find_links, pip_install_local
from tests.lib import tests_data, reset_env, pyversion_nodot, path_to_url, find_links
def test_pip_wheel_fails_without_wheel():
"""
Test 'pip wheel' fails without wheel
"""
env = reset_env()
result = run_pip('wheel', '--no-index', '-f', find_links, 'simple==3.0', expect_error=True)
script = reset_env()
result = script.pip('wheel', '--no-index', '-f', find_links, 'simple==3.0', expect_error=True)
assert "'pip wheel' requires bdist_wheel" in result.stdout
def test_pip_wheel_success():
"""
Test 'pip wheel' success.
"""
env = reset_env()
pip_install_local('wheel')
result = run_pip('wheel', '--no-index', '-f', find_links, 'simple==3.0')
script = reset_env()
script.pip_install_local('wheel')
result = script.pip('wheel', '--no-index', '-f', find_links, 'simple==3.0')
wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name
wheel_file_path = script.scratch/'wheelhouse'/wheel_file_name
assert wheel_file_path in result.files_created, result.stdout
assert "Successfully built simple" in result.stdout, result.stdout
......@@ -35,11 +35,11 @@ def test_pip_wheel_fail():
"""
Test 'pip wheel' failure.
"""
env = reset_env()
pip_install_local('wheel')
result = run_pip('wheel', '--no-index', '-f', find_links, 'wheelbroken==0.1')
script = reset_env()
script.pip_install_local('wheel')
result = script.pip('wheel', '--no-index', '-f', find_links, 'wheelbroken==0.1')
wheel_file_name = 'wheelbroken-0.1-py%s-none-any.whl' % pyversion_nodot
wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name
wheel_file_path = script.scratch/'wheelhouse'/wheel_file_name
assert wheel_file_path not in result.files_created, (wheel_file_path, result.files_created)
assert "FakeError" in result.stdout, result.stdout
assert "Failed to build wheelbroken" in result.stdout, result.stdout
......@@ -49,19 +49,19 @@ def test_pip_wheel_ignore_wheels_editables():
"""
Test 'pip wheel' ignores editables and *.whl files in requirements
"""
env = reset_env()
pip_install_local('wheel')
script = reset_env()
script.pip_install_local('wheel')
local_wheel = '%s/simple.dist-0.1-py2.py3-none-any.whl' % find_links
local_editable = os.path.abspath(os.path.join(tests_data, 'packages', 'FSPkg'))
write_file('reqs.txt', textwrap.dedent("""\
script.scratch_path.join("reqs.txt").write(textwrap.dedent("""\
%s
-e %s
simple
""" % (local_wheel, local_editable)))
result = run_pip('wheel', '--no-index', '-f', find_links, '-r', env.scratch_path / 'reqs.txt')
result = script.pip('wheel', '--no-index', '-f', find_links, '-r', script.scratch_path / 'reqs.txt')
wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion_nodot
wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name
wheel_file_path = script.scratch/'wheelhouse'/wheel_file_name
assert wheel_file_path in result.files_created, (wheel_file_path, result.files_created)
assert "Successfully built simple" in result.stdout, result.stdout
assert "Failed to build" not in result.stdout, result.stdout
......@@ -77,10 +77,10 @@ def test_no_clean_option_blocks_cleaning_after_wheel():
"""
Test --no-clean option blocks cleaning after wheel build
"""
env = reset_env()
pip_install_local('wheel')
result = run_pip('wheel', '--no-clean', '--no-index', '--find-links=%s' % find_links, 'simple')
build = env.venv_path/'build'/'simple'
script = reset_env()
script.pip_install_local('wheel')
result = script.pip('wheel', '--no-clean', '--no-index', '--find-links=%s' % find_links, 'simple')
build = script.venv_path/'build'/'simple'
assert exists(build), "build/simple should still exist %s" % str(result)
......@@ -89,12 +89,10 @@ def test_pip_wheel_source_deps():
Test 'pip wheel --use-wheel' finds and builds source archive dependencies of wheels
"""
# 'requires_source' is a wheel that depends on the 'source' project
env = reset_env()
pip_install_local('wheel')
result = run_pip('wheel', '--use-wheel', '--no-index', '-f', find_links, 'requires_source')
script = reset_env()
script.pip_install_local('wheel')
result = script.pip('wheel', '--use-wheel', '--no-index', '-f', find_links, 'requires_source')
wheel_file_name = 'source-1.0-py%s-none-any.whl' % pyversion_nodot
wheel_file_path = env.scratch/'wheelhouse'/wheel_file_name
wheel_file_path = script.scratch/'wheelhouse'/wheel_file_name
assert wheel_file_path in result.files_created, result.stdout
assert "Successfully built source" in result.stdout, result.stdout
此差异已折叠。
import textwrap
from tests.lib import (mkdir, write_file,)
def _create_test_package_submodule(env):
mkdir('version_pkg_submodule')
env.scratch_path.join("version_pkg_submodule").mkdir()
submodule_path = env.scratch_path/'version_pkg_submodule'
env.run('touch', 'testfile', cwd=submodule_path)
env.run('git', 'init', cwd=submodule_path)
......@@ -13,8 +13,8 @@ def _create_test_package_submodule(env):
return submodule_path
def _change_test_package_submodule(env, submodule_path):
write_file(submodule_path/'testfile', 'this is a changed file')
write_file(submodule_path/'testfile2', 'this is an added file')
submodule_path.join("testfile").write("this is a changed file")
submodule_path.join("testfile2").write("this is an added file")
env.run('git', 'add', '.', cwd=submodule_path)
env.run('git', 'commit', '-q',
'--author', 'Pip <python-virtualenv@googlegroups.com>',
......@@ -27,23 +27,23 @@ def _pull_in_submodule_changes_to_module(env, module_path):
'-am', 'submodule change', cwd=module_path)
def _create_test_package_with_submodule(env):
mkdir('version_pkg')
env.scratch_path.join("version_pkg").mkdir()
version_pkg_path = env.scratch_path/'version_pkg'
mkdir(version_pkg_path/'testpkg')
version_pkg_path.join("testpkg").mkdir()
pkg_path = version_pkg_path/'testpkg'
write_file('__init__.py', '# hello there', pkg_path)
write_file('version_pkg.py', textwrap.dedent('''\
pkg_path.join("__init__.py").write("# hello there")
pkg_path.join("version_pkg.py").write(textwrap.dedent('''\
def main():
print('0.1')
'''), pkg_path)
write_file('setup.py', textwrap.dedent('''\
'''))
version_pkg_path.join("setup.py").write(textwrap.dedent('''\
from setuptools import setup, find_packages
setup(name='version_pkg',
version='0.1',
packages=find_packages(),
)
'''), version_pkg_path)
'''))
env.run('git', 'init', cwd=version_pkg_path, expect_error=True)
env.run('git', 'add', '.', cwd=version_pkg_path, expect_error=True)
env.run('git', 'commit', '-q',
......
......@@ -3,7 +3,6 @@ import subprocess
from pip.vcs import subversion, git, bazaar, mercurial
from pip.backwardcompat import urlretrieve
from tests.lib import path_to_url
from tests.lib.pypi_server import PyPIProxy
if hasattr(subprocess, "check_call"):
......@@ -12,6 +11,9 @@ else:
subprocess_call = subprocess.call
CACHE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests_cache')
def _create_initools_repository():
subprocess_call('svnadmin create INITools'.split(), cwd=_get_vcs_folder())
......@@ -35,10 +37,9 @@ def _create_svn_repository_for_initools():
def _get_vcs_folder():
folder_name = PyPIProxy.CACHE_PATH
if not os.path.exists(folder_name):
os.mkdir(folder_name)
return folder_name
if not os.path.exists(CACHE_PATH):
os.mkdir(CACHE_PATH)
return CACHE_PATH
def _get_vcs_and_checkout_url(remote_repository):
......
# -*- coding: utf-8 -*-
# Author: Aziz Köksal
import glob
import os
import sys
import shutil
try:
from os import supports_fd
except ImportError:
supports_fd = set()
if sys.version_info >= (3,):
unicode = str
u = str
......@@ -13,15 +19,17 @@ else:
_base = os.path.supports_unicode_filenames and unicode or str
from pip.util import rmtree
class Path(_base):
""" Models a path in an object oriented way. """
"""
Models a path in an object oriented way.
"""
sep = os.sep # File system path separator: '/' or '\'.
pathsep = os.pathsep # Separator in the PATH environment variable.
string = _base
# File system path separator: '/' or '\'.
sep = os.sep
# Separator in the PATH environment variable.
pathsep = os.pathsep
def __new__(cls, *paths):
if len(paths):
......@@ -29,49 +37,74 @@ class Path(_base):
return _base.__new__(cls)
def __div__(self, path):
""" Joins this path with another path. """
""" path_obj / 'bc.d' """
""" path_obj / path_obj2 """
"""
Joins this path with another path.
>>> path_obj / 'bc.d'
>>> path_obj / path_obj2
"""
return Path(self, path)
__truediv__ = __div__
def __rdiv__(self, path):
""" Joins this path with another path. """
""" "/home/a" / path_obj """
"""
Joins this path with another path.
>>> "/home/a" / path_obj
"""
return Path(path, self)
__rtruediv__ = __rdiv__
def __idiv__(self, path):
""" Like __div__ but also assigns to the variable. """
""" path_obj /= 'bc.d' """
"""
Like __div__ but also assigns to the variable.
>>> path_obj /= 'bc.d'
"""
return Path(self, path)
__itruediv__ = __idiv__
def __floordiv__(self, paths):
""" Returns a list of paths prefixed with 'self'. """
""" '/home/a' // [bc.d, ef.g] -> [/home/a/bc.d, /home/a/ef.g] """
"""
Returns a list of paths prefixed with 'self'.
>>> '/home/a' // [bc.d, ef.g]
[/home/a/bc.d, /home/a/ef.g]
"""
return [Path(self, path) for path in paths]
def __sub__(self, path):
""" Makes this path relative to another path. """
""" path_obj - '/home/a' """
""" path_obj - path_obj2 """
"""
Makes this path relative to another path.
>>> path_obj - '/home/a'
>>> path_obj - path_obj2
"""
return Path(os.path.relpath(self, path))
def __rsub__(self, path):
""" Returns path relative to this path. """
""" "/home/a" - path_obj """
"""
Returns path relative to this path.
>>> "/home/a" - path_obj
"""
return Path(os.path.relpath(path, self))
def __add__(self, path):
""" Path('/home/a') + 'bc.d' -> '/home/abc.d' """
"""
>>> Path('/home/a') + 'bc.d'
'/home/abc.d'
"""
return Path(_base(self) + path)
def __radd__(self, path):
""" '/home/a' + Path('bc.d') -> '/home/abc.d' """
"""
>>> '/home/a' + Path('bc.d')
'/home/abc.d'
"""
return Path(path + _base(self))
def __repr__(self):
......@@ -82,128 +115,182 @@ class Path(_base):
@property
def name(self):
""" '/home/a/bc.d' -> 'bc.d' """
"""
'/home/a/bc.d' -> 'bc.d'
"""
return os.path.basename(self)
@property
def namebase(self):
""" '/home/a/bc.d' -> 'bc' """
"""
'/home/a/bc.d' -> 'bc'
"""
return self.noext.name
@property
def noext(self):
""" '/home/a/bc.d' -> '/home/a/bc' """
"""
'/home/a/bc.d' -> '/home/a/bc'
"""
return Path(os.path.splitext(self)[0])
@property
def ext(self):
""" '/home/a/bc.d' -> '.d' """
"""
'/home/a/bc.d' -> '.d'
"""
return Path(os.path.splitext(self)[1])
@property
def abspath(self):
""" './a/bc.d' -> '/home/a/bc.d' """
"""
'./a/bc.d' -> '/home/a/bc.d'
"""
return Path(os.path.abspath(self))
@property
def realpath(self):
""" Resolves symbolic links. """
"""
Resolves symbolic links.
"""
return Path(os.path.realpath(self))
@property
def normpath(self):
""" '/home/x/.././a//bc.d' -> '/home/a/bc.d' """
"""
'/home/x/.././a//bc.d' -> '/home/a/bc.d'
"""
return Path(os.path.normpath(self))
@property
def normcase(self):
""" Deals with case-insensitive filesystems """
"""
Deals with case-insensitive filesystems
"""
return Path(os.path.normcase(self))
@property
def folder(self):
""" Returns the folder of this path. """
""" '/home/a/bc.d' -> '/home/a' """
""" '/home/a/' -> '/home/a' """
""" '/home/a' -> '/home' """
"""
Returns the folder of this path.
'/home/a/bc.d' -> '/home/a'
'/home/a/' -> '/home/a'
'/home/a' -> '/home'
"""
return Path(os.path.dirname(self))
@property
def exists(self):
""" Returns True if the path exists. """
"""
Returns True if the path exists.
"""
return os.path.exists(self)
@property
def atime(self):
""" Returns last accessed time. """
"""
Returns last accessed time.
"""
return os.path.getatime(self)
@property
def mtime(self):
""" Returns last modified time. """
"""
Returns last modified time.
"""
return os.path.getmtime(self)
@property
def ctime(self):
""" Returns last changed time. """
"""
Returns last changed time.
"""
return os.path.getctime(self)
@classmethod
def supports_unicode(self):
""" Returns True if the system can handle Unicode file names. """
"""
Returns True if the system can handle Unicode file names.
"""
return os.path.supports_unicode_filenames()
def walk(self, **kwargs):
""" Returns a generator that walks through a directory tree. """
if "followlinks" in kwargs:
from sys import version_info as vi
if vi[0]*10+vi[1] < 26: # Only Python 2.6 or newer supports followlinks
del kwargs["followlinks"]
return os.walk(self, **kwargs)
def mkdir(self, mode=0x1FF): # 0o777
""" Creates a directory, if it doesn't exist already. """
def mkdir(self, mode=0x1FF): # 0o777
"""
Creates a directory, if it doesn't exist already.
"""
if not self.exists:
os.mkdir(self, mode)
return self
def makedirs(self, mode=0x1FF): # 0o777
""" Like mkdir(), but also creates parent directories. """
def makedirs(self, mode=0x1FF): # 0o777
"""
Like mkdir(), but also creates parent directories.
"""
if not self.exists:
os.makedirs(self, mode)
return self
def remove(self):
""" Removes a file. """
os.remove(self)
rm = remove # Alias.
"""
Removes a file.
"""
return os.remove(self)
rm = remove # Alias.
def rmdir(self):
""" Removes a directory. """
"""
Removes a directory.
"""
return os.rmdir(self)
def rmtree(self, noerrors=True):
""" Removes a directory tree. Ignores errors by default. """
return rmtree(self, ignore_errors=noerrors)
"""
Removes a directory tree. Ignores errors by default.
"""
return shutil.rmtree(self, ignore_errors=noerrors)
def copy(self, to):
shutil.copy(self, to)
return shutil.copy(self, to)
def copytree(self, to):
""" Copies a directory tree to another path. """
shutil.copytree(self, to)
"""
Copies a directory tree to another path.
"""
return shutil.copytree(self, to)
def move(self, to):
""" Moves a file or directory to another path. """
shutil.move(self, to)
"""
Moves a file or directory to another path.
"""
return shutil.move(self, to)
def rename(self, to):
""" Renames a file or directory. May throw an OSError. """
os.rename(self, to)
"""
Renames a file or directory. May throw an OSError.
"""
return os.rename(self, to)
def renames(self, to):
os.renames(self, to)
return os.renames(self, to)
def glob(self, pattern):
from glob import glob
return list(map(Path, glob(_base(self/pattern))))
return (Path(i) for i in glob.iglob(self.join(pattern)))
def join(self, *parts):
return Path(self, *parts)
def write(self, content):
with open(self, "w") as fp:
fp.write(content)
def touch(self, times=None):
with open(self, "a") as fp:
os.utime(fp.fileno() if os.utime in supports_fd else self, times)
curdir = Path(os.path.curdir)
import os
import sys
import pip.backwardcompat
from pip.backwardcompat import urllib, string_types, b, u, emailmessage
urlopen_original = pip.backwardcompat.urllib2.urlopen
class CachedResponse(object):
"""
CachedResponse always cache url access and returns the cached response.
It returns an object compatible with ``urllib.addinfourl``,
it means the object is like the result of a call like::
>>> response = urllib2.urlopen('http://example.com')
"""
def __init__(self, url, folder):
self.headers = emailmessage.Message()
# patch due to setuptools>=0.7 header processing
# easy_install fails w/o this on windows/py2
# https://github.com/pypa/pip/issues/946#issuecomment-20860320
if sys.version_info < (3,):
def getheaders(key):
return self.headers.get_all(key)
self.headers.getheaders = getheaders
self.code = 500
self.msg = 'Internal Server Error'
# url can be a simple string, or a urllib2.Request object
if isinstance(url, string_types):
self.url = url
else:
self.url = url.get_full_url()
for key, value in url.headers.items():
self.headers[key] = value
self._body = b('')
self._set_all_fields(folder)
def _set_all_fields(self, folder):
filename = os.path.join(folder, urllib.quote(self.url, ''))
if not os.path.exists(filename):
self._cache_url(filename)
fp = open(filename, 'rb')
try:
line = fp.readline().strip()
self.code, self.msg = line.split(None, 1)
except ValueError:
raise ValueError('Bad field line: %r' % line)
self.code = int(self.code)
self.msg = u(self.msg)
for line in fp:
if line == b('\n'):
break
key, value = line.split(b(': '), 1)
self.headers[u(key)] = u(value.strip())
for line in fp:
self._body += line
fp.close()
def getcode(self):
return self.code
def geturl(self):
return self.url
def info(self):
return self.headers
def read(self, bytes=None):
"""
it can read a chunk of bytes or everything
"""
if bytes:
result = self._body[:bytes]
self._body = self._body[bytes:]
return result
return self._body
def close(self):
pass
def _cache_url(self, filepath):
response = urlopen_original(self.url)
fp = open(filepath, 'wb')
# when it uses file:// scheme, code is None and there is no msg attr
# but it has been successfully opened
status = b('%s %s' % (getattr(response, 'code', 200) or 200, getattr(response, 'msg', 'OK')))
headers = [b('%s: %s' % (key, value)) for key, value in list(response.headers.items())]
body = response.read()
fp.write(b('\n').join([status] + headers + [b(''), body]))
fp.close()
class PyPIProxy(object):
CACHE_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'tests_cache')
@classmethod
def setup(cls):
instance = cls()
instance._create_cache_folder()
instance._monkey_patch_urllib2_to_cache_everything()
def _monkey_patch_urllib2_to_cache_everything(self):
def urlopen(url):
return CachedResponse(url, self.CACHE_PATH)
pip.backwardcompat.urllib2.urlopen = urlopen
def _create_cache_folder(self):
if not os.path.exists(self.CACHE_PATH):
os.mkdir(self.CACHE_PATH)
def assert_equal(a, b):
assert a == b, "\nexpected:\n%r\ngot:\n%r" % (b, a)
def test_cache_proxy():
url = 'http://example.com'
here = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(here, urllib.quote(url, ''))
if os.path.exists(filepath):
os.remove(filepath)
response = pip.backwardcompat.urllib2.urlopen(url)
r = CachedResponse(url, here)
try:
assert_equal(r.code, response.code)
assert_equal(r.msg, response.msg)
assert_equal(r.read(), response.read())
assert_equal(r.url, response.url)
assert_equal(r.geturl(), response.geturl())
assert_equal(set(r.headers.keys()), set(response.headers.keys()))
assert_equal(set(r.info().keys()), set(response.info().keys()))
assert_equal(r.headers['content-length'], response.headers['content-length'])
finally:
os.remove(filepath)
"""Test the test support."""
import filecmp
import imp
import os
import re
import sys
from os.path import join, isdir
from pip.backwardcompat import uses_pycache
from tests.lib import tests_lib, reset_env, run_pip, src_folder
patch_urlopen = """
def mock_isdir(d):
pass
import os
os.path.isdir = mock_isdir
"""
def test_pypiproxy_patch_applied():
"""
Test the PyPIProxy.setup() patch was applied, and sys.path returned to normal
"""
env = reset_env()
result = env.run('python', '-c', "import pip; print(pip.backwardcompat.urllib2.urlopen.__module__)")
#if it were not patched, the result would be 'urllib2'
assert "pypi_server"== result.stdout.strip(), result.stdout
#confirm the temporary sys.path adjustment is gone
result = env.run('python', '-c', "import sys; print(sys.path)")
paths = eval(result.stdout.strip())
assert tests_lib not in paths, paths
class Test_reset_env:
def setup(self):
# create a TestPipEnvironment env and add a file to the backup
self.env = reset_env()
self.test_file = self.env.backup_path / self.env.venv / 'test_file'
f = open(self.test_file, 'w')
f.close()
def teardown(self):
if os.path.isfile(self.test_file):
self.test_file.rm()
def test_cache_venv(self):
"""
Test reset_env cache's internal virtualenv
"""
env = reset_env()
assert os.path.isfile(self.test_file)
def test_reset_env_system_site_packages(self):
"""
Test using system_site_packages with reset_env resets the venv cache
"""
env = reset_env(system_site_packages=True)
env = reset_env()
assert not os.path.isfile(self.env.backup_path / self.env.venv / 'test_file')
def test_add_patch_to_sitecustomize():
"""
Test adding monkey patch snippet to sitecustomize.py (using TestPipEnvironment)
"""
env = reset_env(sitecustomize=patch_urlopen)
if uses_pycache:
# caught py32 with an outdated __pycache__ file after a sitecustomize update (after python should have updated it)
# https://github.com/pypa/pip/pull/893#issuecomment-16426701
# now we delete the cache file to be sure in TestPipEnvironment._add_to_sitecustomize
# it should not exist after creating the env
cache_path = imp.cache_from_source(env.lib_path / 'sitecustomize.py')
assert not os.path.isfile(cache_path)
debug_content = open(env.lib_path / 'sitecustomize.py').read()
result = env.run('python', '-c', "import os; print(os.path.isdir.__module__)")
if uses_pycache:
# if this next assert fails, let's have the modified time to look at
cache_path = imp.cache_from_source(env.lib_path / 'sitecustomize.py')
src_mtime = os.stat(env.lib_path / 'sitecustomize.py').st_mtime
cache_mtime = os.stat(cache_path).st_mtime
debug_content += "src mtime: %s, cache mtime: %s" % (src_mtime, cache_mtime)
assert "sitecustomize" == result.stdout.strip(), result.stdout
def test_sitecustomize_not_growing_in_fast_environment():
"""
Test that the sitecustomize is not growing with redundant patches in the cached fast environment
"""
patch = "fu = 'bar'"
env1 = reset_env(sitecustomize=patch)
sc1 = env1.lib_path / 'sitecustomize.py'
size1 = os.stat(sc1).st_size
env2 = reset_env(sitecustomize=patch)
sc2 = env2.lib_path / 'sitecustomize.py'
size2 = os.stat(sc2).st_size
assert size1==size2, "size before, %d != size after, %d" %(size1, size2)
from tests.lib import reset_env, src_folder
def test_tmp_dir_exists_in_env():
......@@ -121,11 +21,11 @@ def test_correct_pip_version():
"""
Check we are running proper version of pip in run_pip.
"""
reset_env()
script = reset_env()
# output is like:
# pip PIPVERSION from PIPDIRECTORY (python PYVERSION)
result = run_pip('--version')
result = script.pip('--version')
# compare the directory tree of the invoked pip with that of this source distribution
dir = re.match(r'pip \d(\.[\d])+(\.?(rc|dev|pre|post)\d+)? from (.*) \(python \d(.[\d])+\)$',
......
......@@ -3,7 +3,7 @@ from pip.backwardcompat import urllib
from tests.lib.path import Path
from pip.index import package_to_requirement, HTMLPage
from pip.index import PackageFinder, Link, InfLink
from tests.lib import reset_env, run_pip, pyversion, tests_data, path_to_url, find_links
from tests.lib import tests_data, path_to_url, find_links
from string import ascii_lowercase
from mock import patch
......
......@@ -12,9 +12,9 @@ import pytest
from mock import Mock, patch
from pip.exceptions import BadCommand
from pip.util import (egg_link_path, Inf, get_installed_distributions, find_command,
untar_file, unzip_file)
from tests.lib import reset_env, mkdir, write_file, tests_data
from pip.util import (egg_link_path, Inf, get_installed_distributions,
find_command, untar_file, unzip_file)
from tests.lib import reset_env, tests_data
class Tests_EgglinkPath:
......@@ -203,19 +203,22 @@ class Tests_get_installed_distributions:
assert len(dists) == 3
def test_find_command_folder_in_path():
def test_find_command_folder_in_path(monkeypatch):
"""
If a folder named e.g. 'git' is in PATH, and find_command is looking for
the 'git' executable, it should not match the folder, but rather keep
looking.
"""
env = reset_env()
mkdir('path_one')
path_one = env.scratch_path/'path_one'
mkdir(path_one/'foo')
mkdir('path_two')
path_two = env.scratch_path/'path_two'
write_file(path_two/'foo', '# nothing')
# Why in the world is this needed?
monkeypatch.setattr(shutil, "_use_fd_functions", False, raising=False)
script = reset_env()
script.scratch_path.join("path_one").mkdir()
path_one = script.scratch_path/'path_one'
path_one.join("foo").mkdir()
script.scratch_path.join("path_two").mkdir()
path_two = script.scratch_path/'path_two'
path_two.join("foo").write("# nothing")
found_path = find_command('foo', map(str, [path_one, path_two]))
assert found_path == path_two/'foo'
......
......@@ -6,7 +6,7 @@ envlist =
deps=
pytest
mock
scripttest>=1.1.1
scripttest>=1.3
git+https://github.com/pypa/virtualenv@develop#egg=virtualenv
commands =
py.test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册