Skip to content

Commit

Permalink
Rework tests to isolate the currently reused wheelhouse directory
Browse files Browse the repository at this point in the history
utils is now a fixture providing tmp_path to run cibuildwheel
  • Loading branch information
mayeut committed Nov 16, 2019
1 parent 34515b7 commit 56e244f
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 155 deletions.
5 changes: 1 addition & 4 deletions bin/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ def single_run(test_project):
env=env,
)

# clean up
if os.path.exists('wheelhouse'):
shutil.rmtree('wheelhouse')

if __name__ == '__main__':
import argparse
Expand All @@ -33,7 +30,7 @@ def single_run(test_project):
args = parser.parse_args()

project_path = os.path.abspath(args.test_project_dir)

if not os.path.exists(project_path):
print('No test project not found.', file=sys.stderr)
exit(2)
Expand Down
15 changes: 8 additions & 7 deletions test/01_basic/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import os
import utils
from utils import utils


project_dir = os.path.dirname(__file__)
PROJECT_DIR = os.path.dirname(__file__)

def test():

def test(utils):
# build the wheels
utils.cibuildwheel_run(project_dir)
utils.cibuildwheel_run(PROJECT_DIR)

# check that the expected wheels are produced
expected_wheels = utils.expected_wheels('spam', '0.1.0')
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)


def test_build_identifiers():
def test_build_identifiers(utils):
# check that the number of expected wheels matches the number of build
# identifiers
# after adding CIBW_MANYLINUX_IMAGE to support manylinux2010, there
# can be multiple wheels for each wheel, though, so we need to limit
# the expected wheels
expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
if not '-manylinux' in w or '-manylinux1' in w]
build_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir)
build_identifiers = utils.cibuildwheel_get_build_identifiers(PROJECT_DIR)
assert len(expected_wheels) == len(build_identifiers)
30 changes: 14 additions & 16 deletions test/02_test/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os, subprocess
import pytest
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build and test the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_TEST_REQUIRES': 'nose',
# the 'false ||' bit is to ensure this command runs in a shell on
# mac/linux.
Expand All @@ -16,15 +18,13 @@ def test():

# also check that we got the right wheels
expected_wheels = utils.expected_wheels('spam', '0.1.0')
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)


def test_extras_require():
project_dir = os.path.dirname(__file__)

def test_extras_require(utils):
# build and test the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_TEST_EXTRAS': 'test',
# the 'false ||' bit is to ensure this command runs in a shell on
# mac/linux.
Expand All @@ -34,22 +34,20 @@ def test_extras_require():

# also check that we got the right wheels
expected_wheels = utils.expected_wheels('spam', '0.1.0')
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)


def test_failing_test():
def test_failing_test(utils):
'''Ensure a failing test causes cibuildwheel to error out and exit'''
project_dir = os.path.dirname(__file__)

with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_TEST_COMMAND': 'false',
# manylinux1 has a version of bash that's been shown to have
# manylinux1 has a version of bash that's been shown to have
# problems with this, so let's check that.
'CIBW_MANYLINUX_I686_IMAGE': 'manylinux1',
'CIBW_MANYLINUX_X86_64_IMAGE': 'manylinux1',
})

assert len(os.listdir('wheelhouse'))
assert len(utils.list_wheels()) == 0

14 changes: 8 additions & 6 deletions test/03_before_build/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import os
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(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)"''',
})

# also check that we got the right wheels
expected_wheels = utils.expected_wheels('spam', '0.1.0')
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)
12 changes: 7 additions & 5 deletions test/04_build_skip/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import os
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# build the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_BUILD': 'cp3?-*',
'CIBW_SKIP': 'cp37-*',
})

# check that we got the right wheels. There should be no 2.7 or 3.7.
expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
if ('-cp3' in w) and ('-cp37' not in w)]
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)
12 changes: 7 additions & 5 deletions test/05_environment/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import os
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# write some information into the CIBW_ENVIRONMENT, for expansion and
# insertion into the environment by cibuildwheel. This is checked
# in setup.py
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(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"''',
})

# also check that we got the right wheels built
expected_wheels = utils.expected_wheels('spam', '0.1.0')
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)
12 changes: 7 additions & 5 deletions test/06_docker_images/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os, pytest
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
if utils.platform != 'linux':
pytest.skip('the test is only relevant to the linux build')

utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_MANYLINUX_X86_64_IMAGE': 'dockcross/manylinux2010-x64',
'CIBW_MANYLINUX_I686_IMAGE': 'dockcross/manylinux1-x86',
'CIBW_BEFORE_BUILD': '/opt/python/cp36-cp36m/bin/pip install -U auditwheel', # Currently necessary on dockcross images to get auditwheel 2.1 supporting AUDITWHEEL_PLAT
Expand All @@ -17,5 +19,5 @@ def test():
# also check that we got the right wheels built
expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
if '-manylinux2010_i686' not in w]
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)
11 changes: 7 additions & 4 deletions test/07_ssl/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
# this test checks that SSL is working in the build environment using
# some checks in setup.py.

utils.cibuildwheel_run(project_dir)
utils.cibuildwheel_run(PROJECT_DIR)
16 changes: 9 additions & 7 deletions test/08_manylinux2010_only/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import os, pytest
import utils
from utils import utils

def test():
project_dir = os.path.dirname(__file__)

PROJECT_DIR = os.path.dirname(__file__)


def test(utils):
if utils.platform != 'linux':
pytest.skip('the docker test is only relevant to the linux build')

# build the wheels
# CFLAGS environment veriable is ecessary to fail on 'malloc_info' (on manylinux1) during compilation/linking,
# rather than when dynamically loading the Python
utils.cibuildwheel_run(project_dir, add_env={
# rather than when dynamically loading the Python
utils.cibuildwheel_run(PROJECT_DIR, add_env={
'CIBW_ENVIRONMENT': 'CFLAGS="$CFLAGS -Werror=implicit-function-declaration"',
})

# also check that we got the right wheels
expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
if not '-manylinux' in w or '-manylinux2010' in w]
actual_wheels = os.listdir('wheelhouse')
actual_wheels = utils.list_wheels()
assert set(actual_wheels) == set(expected_wheels)
Loading

0 comments on commit 56e244f

Please sign in to comment.