From e87032c830fc65bd25465565b96400618b3ed7d8 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Tue, 23 Apr 2019 22:14:17 +0100 Subject: [PATCH] Rework tests check all wheels produced against a reference list Also, wrap the cibuildwheel call to make building env easier --- test/01_basic/cibuildwheel_test.py | 55 +++++----------- test/02_test/cibuildwheel_test.py | 20 +++--- test/03_before_build/cibuildwheel_test.py | 24 +++---- test/04_build_skip/cibuildwheel_test.py | 49 +++------------ test/05_environment/cibuildwheel_test.py | 20 +++--- test/06_docker_images/cibuildwheel_test.py | 20 ++---- test/07_ssl/cibuildwheel_test.py | 11 +--- test/shared/utils.py | 73 +++++++++++++++++++++- 8 files changed, 126 insertions(+), 146 deletions(-) diff --git a/test/01_basic/cibuildwheel_test.py b/test/01_basic/cibuildwheel_test.py index 008b8086..93c67829 100644 --- a/test/01_basic/cibuildwheel_test.py +++ b/test/01_basic/cibuildwheel_test.py @@ -1,49 +1,22 @@ -import subprocess, sys, os -from glob import glob +import os import utils + +project_dir = os.path.dirname(__file__) + def test(): - project_dir = os.path.dirname(__file__) - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir]) - - # check that every wheel is produced - if utils.platform == 'linux': - assert glob('wheelhouse/*-cp27-cp27m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp27-cp27mu-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp34-cp34m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp35-cp35m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp36-cp36m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp37-cp37m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp27-cp27m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp27-cp27mu-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp34-cp34m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp35-cp35m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp36-cp36m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp37-cp37m-manylinux1_i686.whl') + utils.cibuildwheel_run(project_dir) - if utils.platform == 'windows': - assert glob('wheelhouse/*-cp27-*-win32.whl') - assert glob('wheelhouse/*-cp34-*-win32.whl') - assert glob('wheelhouse/*-cp35-*-win32.whl') - assert glob('wheelhouse/*-cp36-*-win32.whl') - assert glob('wheelhouse/*-cp37-*-win32.whl') - assert glob('wheelhouse/*-cp27-*-win_amd64.whl') - assert glob('wheelhouse/*-cp34-*-win_amd64.whl') - assert glob('wheelhouse/*-cp35-*-win_amd64.whl') - assert glob('wheelhouse/*-cp36-*-win_amd64.whl') - assert glob('wheelhouse/*-cp37-*-win_amd64.whl') + # check that the expected wheels are produced + expected_wheels = utils.expected_wheels('spam', '0.1.0') + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) - if utils.platform == 'macos': - assert glob('wheelhouse/*-cp27-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp34-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp35-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp36-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp37-*-macosx_10_6_intel.whl') - # also check that the number of built wheels matches the number of build +def test_build_identifiers(): + # check that the number of expected wheels matches the number of build # identifiers - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + expected_wheels = utils.expected_wheels('spam', '0.1.0') + build_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) + assert len(expected_wheels) == len(build_identifiers) diff --git a/test/02_test/cibuildwheel_test.py b/test/02_test/cibuildwheel_test.py index e70b0172..005ee68b 100644 --- a/test/02_test/cibuildwheel_test.py +++ b/test/02_test/cibuildwheel_test.py @@ -1,23 +1,19 @@ -import subprocess, sys, os -from glob import glob +import os import utils def test(): project_dir = os.path.dirname(__file__) - # set up the environment - env = os.environ.copy() - env.update({ + + # build and test the wheels + utils.run_cibuildwheel(project_dir, add_env={ 'CIBW_TEST_REQUIRES': 'nose', # the 'false ||' bit is to ensure this command runs in a shell on # mac/linux. 'CIBW_TEST_COMMAND': 'false || nosetests {project}/test', 'CIBW_TEST_COMMAND_WINDOWS': 'nosetests {project}/test', }) - - # build & test the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir], env=env) - # also check that we got the right number of built wheels - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + # also check that we got the right wheels + expected_wheels = utils.expected_wheels('spam', '0.1.0') + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/03_before_build/cibuildwheel_test.py b/test/03_before_build/cibuildwheel_test.py index cbf902b4..6bb0872f 100644 --- a/test/03_before_build/cibuildwheel_test.py +++ b/test/03_before_build/cibuildwheel_test.py @@ -1,22 +1,18 @@ -import subprocess, sys, os -from glob import glob +import os import utils def test(): project_dir = os.path.dirname(__file__) - # set up the environment - env = os.environ.copy() - # write python version information to a temporary file, this is checked - # in setup.py - env.update({ + + # build the wheels + utils.run_cibuildwheel(project_dir, add_env={ + # write python version information to a temporary file, this is + # checked in setup.py 'CIBW_BEFORE_BUILD': '''python -c "import sys; open('/tmp/pythonversion.txt', 'w').write(sys.version)" && python -c "import sys; open('/tmp/pythonexecutable.txt', 'w').write(sys.executable)"''', 'CIBW_BEFORE_BUILD_WINDOWS': '''python -c "import sys; open('c:\\pythonversion.txt', 'w').write(sys.version)" && python -c "import sys; open('c:\\pythonexecutable.txt', 'w').write(sys.executable)"''', }) - - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir], env=env) - # check that we got the right number of built wheels - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + # also check that we got the right wheels + expected_wheels = utils.expected_wheels('spam', '0.1.0') + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/04_build_skip/cibuildwheel_test.py b/test/04_build_skip/cibuildwheel_test.py index 961d6e2d..06c7e41e 100644 --- a/test/04_build_skip/cibuildwheel_test.py +++ b/test/04_build_skip/cibuildwheel_test.py @@ -1,50 +1,17 @@ -import subprocess, sys, os -from glob import glob +import os import utils def test(): project_dir = os.path.dirname(__file__) - - # set up the environment - env = os.environ.copy() - env.update({ + + # build the wheels + utils.run_cibuildwheel(project_dir, add_env={ 'CIBW_BUILD': 'cp3?-*', 'CIBW_SKIP': 'cp34-*', }) - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir], env=env) - # check that we got the right wheels. There should be no 2.7 or 3.4. - if utils.platform == 'linux': - assert not glob('wheelhouse/*-cp27-cp27m-manylinux1_x86_64.whl') - assert not glob('wheelhouse/*-cp27-cp27mu-manylinux1_x86_64.whl') - assert not glob('wheelhouse/*-cp34-cp34m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp35-cp35m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp36-cp36m-manylinux1_x86_64.whl') - assert glob('wheelhouse/*-cp37-cp37m-manylinux1_x86_64.whl') - assert not glob('wheelhouse/*-cp27-cp27m-manylinux1_i686.whl') - assert not glob('wheelhouse/*-cp27-cp27mu-manylinux1_i686.whl') - assert not glob('wheelhouse/*-cp34-cp34m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp35-cp35m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp36-cp36m-manylinux1_i686.whl') - assert glob('wheelhouse/*-cp37-cp37m-manylinux1_i686.whl') - - if utils.platform == 'windows': - assert not glob('wheelhouse/*-cp27-*-win32.whl') - assert not glob('wheelhouse/*-cp34-*-win32.whl') - assert glob('wheelhouse/*-cp35-*-win32.whl') - assert glob('wheelhouse/*-cp36-*-win32.whl') - assert glob('wheelhouse/*-cp37-*-win32.whl') - assert not glob('wheelhouse/*-cp27-*-win_amd64.whl') - assert not glob('wheelhouse/*-cp34-*-win_amd64.whl') - assert glob('wheelhouse/*-cp35-*-win_amd64.whl') - assert glob('wheelhouse/*-cp36-*-win_amd64.whl') - assert glob('wheelhouse/*-cp37-*-win_amd64.whl') - - if utils.platform == 'macos': - assert not glob('wheelhouse/*-cp27-*-macosx_10_6_intel.whl') - assert not glob('wheelhouse/*-cp34-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp35-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp36-*-macosx_10_6_intel.whl') - assert glob('wheelhouse/*-cp37-*-macosx_10_6_intel.whl') + expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0') + if ('-cp3' in w) and ('-cp34' not in w)] + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/05_environment/cibuildwheel_test.py b/test/05_environment/cibuildwheel_test.py index 78e43482..c5b5aad5 100644 --- a/test/05_environment/cibuildwheel_test.py +++ b/test/05_environment/cibuildwheel_test.py @@ -1,24 +1,18 @@ -import subprocess, sys, os -from glob import glob +import os import utils def test(): project_dir = os.path.dirname(__file__) - - # set up the environment - env = os.environ.copy() + # write some information into the CIBW_ENVIRONMENT, for expansion and # insertion into the environment by cibuildwheel. This is checked # in setup.py - env.update({ + utils.run_cibuildwheel(project_dir, add_env={ 'CIBW_ENVIRONMENT': '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH=$PATH:/opt/cibw_test_path''', 'CIBW_ENVIRONMENT_WINDOWS': '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH="$PATH;/opt/cibw_test_path"''', }) - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir], env=env) - - # check that we got the right number of built wheels - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + # also check that we got the right wheels built + expected_wheels = utils.expected_wheels('spam', '0.1.0') + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/06_docker_images/cibuildwheel_test.py b/test/06_docker_images/cibuildwheel_test.py index 428debbc..0d425b03 100644 --- a/test/06_docker_images/cibuildwheel_test.py +++ b/test/06_docker_images/cibuildwheel_test.py @@ -1,5 +1,4 @@ -import subprocess, sys, os, pytest -from glob import glob +import os, pytest import utils def test(): @@ -8,19 +7,12 @@ def test(): if utils.platform != 'linux': pytest.skip('the docker test is only relevant to the linux build') - # set up the environment - env = os.environ.copy() - # change the docker images to use. The docker image is tested in setup.py - # during the build - env.update({ + utils.run_cibuildwheel(project_dir, add_env={ 'CIBW_MANYLINUX1_X86_64_IMAGE': 'dockcross/manylinux-x64', 'CIBW_MANYLINUX1_I686_IMAGE': 'dockcross/manylinux-x86', }) - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir], env=env) - - # check that we got the right number of built wheels - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + # also check that we got the right wheels built + expected_wheels = utils.expected_wheels('spam', '0.1.0') + actual_wheels = os.listdir('wheelhouse') + assert set(actual_wheels) == set(expected_wheels) diff --git a/test/07_ssl/cibuildwheel_test.py b/test/07_ssl/cibuildwheel_test.py index 97676b3a..fd3fff87 100644 --- a/test/07_ssl/cibuildwheel_test.py +++ b/test/07_ssl/cibuildwheel_test.py @@ -1,5 +1,4 @@ -import subprocess, sys, os -from glob import glob +import os import utils def test(): @@ -7,10 +6,4 @@ def test(): # this test checks that SSL is working in the build environment using # some checks in setup.py. - # build the wheels - subprocess.check_call([sys.executable, '-m', 'cibuildwheel', project_dir]) - - # check that we got the right number of built wheels - expected_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir) - built_wheels = glob('wheelhouse/*.whl') - assert len(built_wheels) == len(expected_identifiers) + utils.cibuildwheel_run(project_dir) diff --git a/test/shared/utils.py b/test/shared/utils.py index fe5c1743..b6a720f5 100644 --- a/test/shared/utils.py +++ b/test/shared/utils.py @@ -4,7 +4,8 @@ Utility functions used by the cibuildwheel tests. This file is added to the PYTHONPATH in the test runner at bin/run_test.py. ''' -import subprocess, sys +import subprocess, sys, os + def cibuildwheel_get_build_identifiers(project_path, env=None): ''' @@ -19,9 +20,77 @@ def cibuildwheel_get_build_identifiers(project_path, env=None): return cmd_output.strip().split('\n') + +def cibuildwheel_run(project_path, env=None, add_env=None): + ''' + Runs cibuildwheel as a subprocess, building the project at project_path. + + Uses the current Python interpreter. + Configure settings using env. + ''' + if env is None: + env = os.environ.copy() + + if add_env is not None: + env.update(add_env) + + subprocess.check_call( + [sys.executable, '-m', 'cibuildwheel', project_path], + env=env, + ) + + +def expected_wheels(package_name, package_version): + ''' + Returns a list of expected wheels from a run of cibuildwheel. + ''' + if platform == 'linux': + templates = [ + '{package_name}-{package_version}-cp27-cp27m-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp27-cp27mu-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp34-cp34m-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp35-cp35m-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp36-cp36m-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp37-cp37m-manylinux1_x86_64.whl', + '{package_name}-{package_version}-cp27-cp27m-manylinux1_i686.whl', + '{package_name}-{package_version}-cp27-cp27mu-manylinux1_i686.whl', + '{package_name}-{package_version}-cp34-cp34m-manylinux1_i686.whl', + '{package_name}-{package_version}-cp35-cp35m-manylinux1_i686.whl', + '{package_name}-{package_version}-cp36-cp36m-manylinux1_i686.whl', + '{package_name}-{package_version}-cp37-cp37m-manylinux1_i686.whl', + ] + elif platform == 'windows': + templates = [ + '{package_name}-{package_version}-cp27-cp27m-win32.whl', + '{package_name}-{package_version}-cp34-cp34m-win32.whl', + '{package_name}-{package_version}-cp35-cp35m-win32.whl', + '{package_name}-{package_version}-cp36-cp36m-win32.whl', + '{package_name}-{package_version}-cp37-cp37m-win32.whl', + '{package_name}-{package_version}-cp27-cp27m-win_amd64.whl', + '{package_name}-{package_version}-cp34-cp34m-win_amd64.whl', + '{package_name}-{package_version}-cp35-cp35m-win_amd64.whl', + '{package_name}-{package_version}-cp36-cp36m-win_amd64.whl', + '{package_name}-{package_version}-cp37-cp37m-win_amd64.whl', + ] + elif platform == 'macos': + templates = [ + '{package_name}-{package_version}-cp27-cp27m-macosx_10_6_intel.whl', + '{package_name}-{package_version}-cp34-cp34m-macosx_10_6_intel.whl', + '{package_name}-{package_version}-cp35-cp35m-macosx_10_6_intel.whl', + '{package_name}-{package_version}-cp36-cp36m-macosx_10_6_intel.whl', + '{package_name}-{package_version}-cp37-cp37m-macosx_10_6_intel.whl', + ] + else: + raise Exception('unsupported platform') + + return [filename.format(package_name=package_name, package_version=package_version) + for filename in templates] + platform = None -if sys.platform.startswith('linux'): +if 'CIBW_PLATFORM' in os.environ: + platform = os.environ['CIBW_PLATFORM'] +elif sys.platform.startswith('linux'): platform = 'linux' elif sys.platform.startswith('darwin'): platform = 'macos'