Skip to content

Commit

Permalink
Run each test using a temporary directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Nov 17, 2019
1 parent 34515b7 commit 16a5423
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 39 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
6 changes: 3 additions & 3 deletions test/01_basic/cibuildwheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

project_dir = os.path.dirname(__file__)

def test():
def test(tmp_path):
# build the wheels
utils.cibuildwheel_run(project_dir)
utils.cibuildwheel_run(project_dir, str(tmp_path))

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


Expand Down
20 changes: 10 additions & 10 deletions test/02_test/cibuildwheel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import pytest
import utils

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

# build and test the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(project_dir, str(tmp_path), 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 +16,15 @@ 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)


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

# build and test the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(project_dir, str(tmp_path), 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,22 @@ 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)


def test_failing_test():
def test_failing_test(tmp_path):
'''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, str(tmp_path), 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(os.listdir(str(tmp_path))) == 0

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

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

# build the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(project_dir, str(tmp_path), 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)
6 changes: 3 additions & 3 deletions test/04_build_skip/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os
import utils

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

# build the wheels
utils.cibuildwheel_run(project_dir, add_env={
utils.cibuildwheel_run(project_dir, str(tmp_path), 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)
6 changes: 3 additions & 3 deletions test/05_environment/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import os
import utils

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

# 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, str(tmp_path), 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)
6 changes: 3 additions & 3 deletions test/06_docker_images/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os, pytest
import utils

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

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, str(tmp_path), 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 +17,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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)
4 changes: 2 additions & 2 deletions test/07_ssl/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import utils

def test():
def test(tmp_path):
project_dir = os.path.dirname(__file__)
# 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, str(tmp_path))
10 changes: 5 additions & 5 deletions test/08_manylinux2010_only/cibuildwheel_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import os, pytest
import utils

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

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, str(tmp_path), 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 = os.listdir(str(tmp_path))
assert set(actual_wheels) == set(expected_wheels)
4 changes: 2 additions & 2 deletions test/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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):
def cibuildwheel_run(project_path, output_dir, env=None, add_env=None):
'''
Runs cibuildwheel as a subprocess, building the project at project_path.
Expand All @@ -38,7 +38,7 @@ def cibuildwheel_run(project_path, env=None, add_env=None):
env.update(add_env)

subprocess.check_call(
[sys.executable, '-m', 'cibuildwheel', project_path],
[sys.executable, '-m', 'cibuildwheel', '--output-dir', output_dir, project_path],
env=env,
)

Expand Down

0 comments on commit 16a5423

Please sign in to comment.