Add a common_wheels fixtures providing wheel & setuptools wheels

This commit is contained in:
Xavier Fernandez 2017-05-14 00:23:17 +02:00
parent 3dd4a0d1ac
commit b709b1ef4a
6 changed files with 119 additions and 89 deletions

View File

@ -1,6 +1,7 @@
import io
import os
import shutil
import subprocess
import sys
import pytest
@ -191,6 +192,18 @@ def script(tmpdir, virtualenv):
)
@pytest.fixture(scope="session")
def common_wheels(tmpdir_factory):
"""Provide a directory with latest setuptools and wheel wheels"""
wheels_dir = tmpdir_factory.mktemp('common_wheels')
subprocess.check_call([
'pip', 'download', 'wheel', 'setuptools',
'-d', str(wheels_dir),
])
yield wheels_dir
wheels_dir.remove(ignore_errors=True)
@pytest.fixture
def data(tmpdir):
return TestData.copy(tmpdir.join("data"))

View File

@ -146,10 +146,8 @@ def test_install_editable_from_svn(script):
result.assert_installed('version-pkg', with_files=['.svn'])
def _test_install_editable_from_git(script, tmpdir, wheel):
def _test_install_editable_from_git(script, tmpdir):
"""Test cloning from Git."""
if wheel:
script.pip('install', 'wheel')
pkg_path = _create_test_package(script, name='testpackage', vcs='git')
args = ['install', '-e', 'git+%s#egg=testpackage' % path_to_url(pkg_path)]
result = script.pip(*args, **{"expect_error": True})
@ -157,12 +155,14 @@ def _test_install_editable_from_git(script, tmpdir, wheel):
def test_install_editable_from_git(script, tmpdir):
_test_install_editable_from_git(script, tmpdir, False)
_test_install_editable_from_git(script, tmpdir)
@pytest.mark.network
def test_install_editable_from_git_autobuild_wheel(script, tmpdir):
_test_install_editable_from_git(script, tmpdir, True)
def test_install_editable_from_git_autobuild_wheel(
script, tmpdir, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
_test_install_editable_from_git(script, tmpdir)
@pytest.mark.network
@ -936,21 +936,21 @@ def test_install_topological_sort(script, data):
@pytest.mark.network
def test_install_wheel_broken(script, data):
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
def test_install_wheel_broken(script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
res = script.pip(
'install', '--no-index', '-f', data.find_links, 'wheelbroken',
'install', '--no-index', '-f', data.find_links, '-f', common_wheels,
'wheelbroken',
expect_stderr=True)
assert "Successfully installed wheelbroken-0.1" in str(res), str(res)
@pytest.mark.network
def test_cleanup_after_failed_wheel(script, data):
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
def test_cleanup_after_failed_wheel(script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
res = script.pip(
'install', '--no-index', '-f', data.find_links, 'wheelbrokenafter',
'install', '--no-index', '-f', data.find_links, '-f', common_wheels,
'wheelbrokenafter',
expect_stderr=True)
# One of the effects of not cleaning up is broken scripts:
script_py = script.bin_path / "script.py"
@ -962,15 +962,14 @@ def test_cleanup_after_failed_wheel(script, data):
@pytest.mark.network
def test_install_builds_wheels(script, data):
def test_install_builds_wheels(script, data, common_wheels):
# NB This incidentally tests a local tree + tarball inputs
# see test_install_editable_from_git_autobuild_wheel for editable
# vcs coverage.
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
to_install = data.packages.join('requires_wheelbroken_upper')
res = script.pip(
'install', '--no-index', '-f', data.find_links,
'install', '--no-index', '-f', data.find_links, '-f', common_wheels,
to_install, expect_stderr=True)
expected = ("Successfully installed requires-wheelbroken-upper-0"
" upper-2.0 wheelbroken-0.1")
@ -1002,12 +1001,13 @@ def test_install_builds_wheels(script, data):
@pytest.mark.network
def test_install_no_binary_disables_building_wheels(script, data):
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
def test_install_no_binary_disables_building_wheels(
script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
to_install = data.packages.join('requires_wheelbroken_upper')
res = script.pip(
'install', '--no-index', '--no-binary=upper', '-f', data.find_links,
'-f', common_wheels,
to_install, expect_stderr=True)
expected = ("Successfully installed requires-wheelbroken-upper-0"
" upper-2.0 wheelbroken-0.1")
@ -1035,12 +1035,11 @@ def test_install_no_binary_disables_building_wheels(script, data):
@pytest.mark.network
def test_install_no_binary_disables_cached_wheels(script, data):
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
def test_install_no_binary_disables_cached_wheels(script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
# Seed the cache
script.pip(
'install', '--no-index', '-f', data.find_links,
'install', '--no-index', '-f', data.find_links, '-f', common_wheels,
'upper')
script.pip('uninstall', 'upper', '-y')
res = script.pip(
@ -1107,7 +1106,7 @@ def test_double_install_fail(script, data):
assert msg in result.stderr
def test_install_incompatible_python_requires(script):
def test_install_incompatible_python_requires(script, common_wheels):
script.scratch_path.join("pkga").mkdir()
pkga_path = script.scratch_path / 'pkga'
pkga_path.join("setup.py").write(textwrap.dedent("""
@ -1116,13 +1115,16 @@ def test_install_incompatible_python_requires(script):
python_requires='<1.0',
version='0.1')
"""))
script.pip('install', 'setuptools>24.2') # This should not be needed
script.pip(
'install', 'setuptools>24.2', # This should not be needed
'--no-index', '-f', common_wheels,
)
result = script.pip('install', pkga_path, expect_error=True)
assert ("pkga requires Python '<1.0' "
"but the running Python is ") in result.stderr
def test_install_incompatible_python_requires_editable(script):
def test_install_incompatible_python_requires_editable(script, common_wheels):
script.scratch_path.join("pkga").mkdir()
pkga_path = script.scratch_path / 'pkga'
pkga_path.join("setup.py").write(textwrap.dedent("""
@ -1131,7 +1133,10 @@ def test_install_incompatible_python_requires_editable(script):
python_requires='<1.0',
version='0.1')
"""))
script.pip('install', 'setuptools>24.2') # This should not be needed
script.pip(
'install', 'setuptools>24.2', # This should not be needed
'--no-index', '-f', common_wheels,
)
result = script.pip(
'install', '--editable=%s' % pkga_path, expect_error=True)
assert ("pkga requires Python '<1.0' "
@ -1139,7 +1144,7 @@ def test_install_incompatible_python_requires_editable(script):
@pytest.mark.network
def test_install_incompatible_python_requires_wheel(script):
def test_install_incompatible_python_requires_wheel(script, common_wheels):
script.scratch_path.join("pkga").mkdir()
pkga_path = script.scratch_path / 'pkga'
pkga_path.join("setup.py").write(textwrap.dedent("""
@ -1148,8 +1153,11 @@ def test_install_incompatible_python_requires_wheel(script):
python_requires='<1.0',
version='0.1')
"""))
script.pip('install', 'setuptools>24.2') # This should not be needed
script.pip('install', 'wheel')
script.pip(
'install', 'setuptools>24.2', # This should not be needed
'--no-index', '-f', common_wheels,
)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
script.run(
'python', 'setup.py', 'bdist_wheel', '--universal', cwd=pkga_path)
result = script.pip('install', './pkga/dist/pkga-0.1-py2.py3-none-any.whl',
@ -1158,7 +1166,7 @@ def test_install_incompatible_python_requires_wheel(script):
"but the running Python is ") in result.stderr
def test_install_compatible_python_requires(script):
def test_install_compatible_python_requires(script, common_wheels):
script.scratch_path.join("pkga").mkdir()
pkga_path = script.scratch_path / 'pkga'
pkga_path.join("setup.py").write(textwrap.dedent("""
@ -1167,7 +1175,10 @@ def test_install_compatible_python_requires(script):
python_requires='>1.0',
version='0.1')
"""))
script.pip('install', 'setuptools>24.2') # This should not be needed
script.pip(
'install', 'setuptools>24.2', # This should not be needed
'--no-index', '-f', common_wheels,
)
res = script.pip('install', pkga_path, expect_error=True)
assert "Successfully installed pkga-0.1" in res.stdout, res

View File

@ -200,8 +200,9 @@ def test_options_from_venv_config(script, virtualenv):
@pytest.mark.network
def test_install_no_binary_via_config_disables_cached_wheels(script, data):
script.pip('install', 'wheel')
def test_install_no_binary_via_config_disables_cached_wheels(
script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
config_file = tempfile.NamedTemporaryFile(mode='wt')
script.environ['PIP_CONFIG_FILE'] = config_file.name
config_file.write(textwrap.dedent("""\

View File

@ -223,10 +223,10 @@ def test_install_local_with_subdirectory(script):
@pytest.mark.network
def test_wheel_user_with_prefix_in_pydistutils_cfg(script, data, virtualenv):
def test_wheel_user_with_prefix_in_pydistutils_cfg(
script, data, virtualenv, common_wheels):
# Make sure wheel is available in the virtualenv
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
virtualenv.system_site_packages = True
homedir = script.environ["HOME"]
script.scratch_path.join("bin").mkdir()
@ -235,8 +235,10 @@ def test_wheel_user_with_prefix_in_pydistutils_cfg(script, data, virtualenv):
[install]
prefix=%s""" % script.scratch_path))
result = script.pip('install', '--user', '--no-index', '-f',
data.find_links, 'requiresupper')
result = script.pip(
'install', '--user', '--no-index',
'-f', data.find_links, '-f', common_wheels,
'requiresupper')
# Check that we are really installing a wheel
assert 'Running setup.py install for requiresupper' not in result.stdout
assert 'installed requiresupper' in result.stdout
@ -339,7 +341,7 @@ def test_constrained_to_url_install_same_url(script, data):
@pytest.mark.network
def test_double_install_spurious_hash_mismatch(script, tmpdir, data):
def test_double_install_spurious_hash_mismatch(script, tmpdir, common_wheels):
"""Make sure installing the same hashed sdist twice doesn't throw hash
mismatch errors.
@ -349,14 +351,14 @@ def test_double_install_spurious_hash_mismatch(script, tmpdir, data):
causes spurious mismatch errors.
"""
script.pip('install', 'wheel') # Otherwise, it won't try to build wheels.
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
# Install wheel package, otherwise, it won't try to build wheels.
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
with requirements_file('simple==1.0 --hash=sha256:393043e672415891885c9a2a'
'0929b1af95fb866d6ca016b42d2e6ce53619b653',
tmpdir) as reqs_file:
# Install a package (and build its wheel):
result = script.pip_install_local(
'--find-links', data.find_links,
'--find-links', data.find_links, '-f', common_wheels,
'-r', reqs_file.abspath, expect_error=False)
assert 'Successfully installed simple-1.0' in str(result)

View File

@ -115,11 +115,11 @@ def test_install_from_wheel_with_headers(script, data):
@pytest.mark.network
def test_install_wheel_with_target(script, data):
def test_install_wheel_with_target(script, data, common_wheels):
"""
Test installing a wheel using pip install --target
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
target_dir = script.scratch_path / 'target'
result = script.pip(
'install', 'simple.dist==0.1', '-t', target_dir,
@ -131,7 +131,7 @@ def test_install_wheel_with_target(script, data):
@pytest.mark.network
def test_install_wheel_with_target_and_data_files(script, data):
def test_install_wheel_with_target_and_data_files(script, data, common_wheels):
"""
Test for issue #4092. It will be checked that a data_files specification in
setup.py is handled correctly when a wheel is installed with the --target
@ -150,7 +150,7 @@ def test_install_wheel_with_target_and_data_files(script, data):
]
)
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
target_dir = script.scratch_path / 'prjwithdatafile'
package = data.packages.join("prjwithdatafile-1.0-py2.py3-none-any.whl")
result = script.pip('install', package,
@ -221,12 +221,12 @@ def test_install_from_wheel_no_deps(script, data):
@pytest.mark.network
def test_install_user_wheel(script, virtualenv, data):
def test_install_user_wheel(script, virtualenv, data, common_wheels):
"""
Test user install from wheel (that has a script)
"""
virtualenv.system_site_packages = True
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip(
'install', 'has.script==1.0', '--user', '--no-index',
'--find-links=' + data.find_links,

View File

@ -20,34 +20,35 @@ def test_pip_wheel_fails_without_wheel(script, data):
assert "'pip wheel' requires the 'wheel' package" in result.stderr
def test_wheel_exit_status_code_when_no_requirements(script):
def test_wheel_exit_status_code_when_no_requirements(script, common_wheels):
"""
Test wheel exit status code when no requirements specified
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip('wheel', expect_error=True)
assert "You must give at least one requirement to wheel" in result.stderr
assert result.returncode == ERROR
def test_wheel_exit_status_code_when_blank_requirements_file(script):
def test_wheel_exit_status_code_when_blank_requirements_file(
script, common_wheels):
"""
Test wheel exit status code when blank requirements file specified
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
script.scratch_path.join("blank.txt").write("\n")
script.pip('wheel', '-r', 'blank.txt')
@pytest.mark.network
def test_pip_wheel_success(script, data):
def test_pip_wheel_success(script, data, common_wheels):
"""
Test 'pip wheel' success.
"""
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, 'simple==3.0',
'wheel', '--no-index', '-f', data.find_links, '-f', common_wheels,
'simple==3.0',
)
wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
@ -56,11 +57,11 @@ def test_pip_wheel_success(script, data):
@pytest.mark.network
def test_pip_wheel_downloads_wheels(script, data):
def test_pip_wheel_downloads_wheels(script, data, common_wheels):
"""
Test 'pip wheel' downloads wheels
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, 'simple.dist',
)
@ -71,27 +72,27 @@ def test_pip_wheel_downloads_wheels(script, data):
@pytest.mark.network
def test_pip_wheel_builds_when_no_binary_set(script, data):
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
def test_pip_wheel_builds_when_no_binary_set(script, data, common_wheels):
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
data.packages.join('simple-3.0-py2.py3-none-any.whl').touch()
# Check that the wheel package is ignored
res = script.pip(
'wheel', '--no-index', '--no-binary', ':all:', '-f', data.find_links,
'wheel', '--no-index', '--no-binary', ':all:',
'-f', data.find_links, '-f', common_wheels,
'simple==3.0')
assert "Running setup.py bdist_wheel for simple" in str(res), str(res)
@pytest.mark.network
def test_pip_wheel_builds_editable_deps(script, data):
def test_pip_wheel_builds_editable_deps(script, data, common_wheels):
"""
Test 'pip wheel' finds and builds dependencies of editables
"""
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
editable_path = os.path.join(data.src, 'requires_simple')
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, '-e', editable_path
'wheel', '--no-index', '-f', data.find_links, '-f', common_wheels,
'-e', editable_path
)
wheel_file_name = 'simple-1.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
@ -99,15 +100,15 @@ def test_pip_wheel_builds_editable_deps(script, data):
@pytest.mark.network
def test_pip_wheel_builds_editable(script, data):
def test_pip_wheel_builds_editable(script, data, common_wheels):
"""
Test 'pip wheel' builds an editable package
"""
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
editable_path = os.path.join(data.src, 'simplewheel-1.0')
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, '-e', editable_path
'wheel', '--no-index', '-f', data.find_links, '-f', common_wheels,
'-e', editable_path
)
wheel_file_name = 'simplewheel-1.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
@ -115,14 +116,14 @@ def test_pip_wheel_builds_editable(script, data):
@pytest.mark.network
def test_pip_wheel_fail(script, data):
def test_pip_wheel_fail(script, data, common_wheels):
"""
Test 'pip wheel' failure.
"""
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, 'wheelbroken==0.1',
'wheel', '--no-index', '-f', data.find_links, '-f', common_wheels,
'wheelbroken==0.1',
expect_error=True,
)
wheel_file_name = 'wheelbroken-0.1-py%s-none-any.whl' % pyversion[0]
@ -137,16 +138,17 @@ def test_pip_wheel_fail(script, data):
@pytest.mark.network
def test_no_clean_option_blocks_cleaning_after_wheel(script, data):
def test_no_clean_option_blocks_cleaning_after_wheel(
script, data, common_wheels):
"""
Test --no-clean option blocks cleaning after wheel build
"""
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
build = script.venv_path / 'build'
result = script.pip(
'wheel', '--no-clean', '--no-index', '--build', build,
'--find-links=%s' % data.find_links, 'simple',
'--find-links=%s' % data.find_links, '-f', common_wheels,
'simple',
expect_temp=True,
)
build = build / 'simple'
@ -154,16 +156,16 @@ def test_no_clean_option_blocks_cleaning_after_wheel(script, data):
@pytest.mark.network
def test_pip_wheel_source_deps(script, data):
def test_pip_wheel_source_deps(script, data, common_wheels):
"""
Test 'pip wheel' finds and builds source archive dependencies
of wheels
"""
# 'requires_source' is a wheel that depends on the 'source' project
script.pip('install', 'wheel')
script.pip('download', 'setuptools', 'wheel', '-d', data.packages)
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
result = script.pip(
'wheel', '--no-index', '-f', data.find_links, 'requires_source',
'wheel', '--no-index', '-f', data.find_links, '-f', common_wheels,
'requires_source',
)
wheel_file_name = 'source-1.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
@ -172,13 +174,14 @@ def test_pip_wheel_source_deps(script, data):
@pytest.mark.network
def test_pip_wheel_fail_cause_of_previous_build_dir(script, data):
def test_pip_wheel_fail_cause_of_previous_build_dir(
script, data, common_wheels):
"""
Test when 'pip wheel' tries to install a package that has a previous build
directory
"""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
# Given that I have a previous build dir of the `simple` package
build = script.venv_path / 'build' / 'simple'
@ -198,9 +201,9 @@ def test_pip_wheel_fail_cause_of_previous_build_dir(script, data):
@pytest.mark.network
def test_wheel_package_with_latin1_setup(script, data):
def test_wheel_package_with_latin1_setup(script, data, common_wheels):
"""Create a wheel from a package with latin-1 encoded setup.py."""
script.pip('install', 'wheel')
script.pip('install', 'wheel', '--no-index', '-f', common_wheels)
pkg_to_wheel = data.packages.join("SetupPyLatin1")
result = script.pip('wheel', pkg_to_wheel)