Ensure tests are up-to-date with master

This commit is contained in:
Joe Rickerby
2020-05-02 22:42:35 +01:00
parent 3b35882f87
commit 007be7aea7
8 changed files with 94 additions and 117 deletions
+29 -32
View File
@@ -26,55 +26,52 @@ def test(tmpdir):
project_with_a_test.generate(project_dir) project_with_a_test.generate(project_dir)
# build and test the wheels # build and test the wheels
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, 'CIBW_TEST_REQUIRES': 'nose',
add_env={ # the 'false ||' bit is to ensure this command runs in a shell on
"CIBW_TEST_REQUIRES": "nose", # mac/linux.
# the 'false ||' bit is to ensure this command runs in a shell on 'CIBW_TEST_COMMAND': 'false || nosetests {project}/test',
# mac/linux. 'CIBW_TEST_COMMAND_WINDOWS': 'COLOR 00 || nosetests {project}/test',
"CIBW_TEST_COMMAND": "false || nosetests {project}/test", })
"CIBW_TEST_COMMAND_WINDOWS": "nosetests {project}/test",
},
)
# also check that we got the right wheels # also check that we got the right wheels
expected_wheels = utils.expected_wheels("spam", "0.1.0") expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
def test_extras_require(tmpdir): def test_extras_require(tmpdir):
project_dir = str(tmpdir) project_dir = str(tmpdir)
project_with_a_test.generate(project_dir) project_with_a_test.generate(project_dir)
# build and test the wheels # build and test the wheels
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, 'CIBW_TEST_EXTRAS': 'test',
add_env={ # the 'false ||' bit is to ensure this command runs in a shell on
"CIBW_TEST_EXTRAS": "test", # mac/linux.
"CIBW_TEST_COMMAND": "nosetests {project}/test", 'CIBW_TEST_COMMAND': 'false || nosetests {project}/test',
}, 'CIBW_TEST_COMMAND_WINDOWS': 'COLOR 00 || nosetests {project}/test',
) })
# also check that we got the right wheels # also check that we got the right wheels
expected_wheels = utils.expected_wheels("spam", "0.1.0") expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
def test_failing_test(tmpdir): def test_failing_test(tmp_path):
"""Ensure a failing test causes cibuildwheel to error out and exit""" """Ensure a failing test causes cibuildwheel to error out and exit"""
project_dir = str(tmpdir) project_dir = str(tmp_path / 'project')
output_dir = str(tmp_path / 'output')
project_with_a_test.generate(project_dir) project_with_a_test.generate(project_dir)
with pytest.raises(subprocess.CalledProcessError): with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run( utils.cibuildwheel_run(project_dir, output_dir=output_dir, add_env={
project_dir, 'CIBW_TEST_COMMAND': 'false',
add_env={ # manylinux1 has a version of bash that's been shown to have
"CIBW_TEST_COMMAND": "false", # problems with this, so let's check that.
# manylinux1 has a version of bash that's been shown to have 'CIBW_MANYLINUX_I686_IMAGE': 'manylinux1',
# problems with this, so let's check that. 'CIBW_MANYLINUX_X86_64_IMAGE': 'manylinux1',
"CIBW_MANYLINUX_I686_IMAGE": "manylinux1", })
"CIBW_MANYLINUX_X86_64_IMAGE": "manylinux1",
}, assert len(os.listdir(output_dir)) == 0
)
assert len(os.listdir("wheelhouse"))
+14 -24
View File
@@ -9,28 +9,21 @@ project_with_before_build_asserts = CTemplateProject(
# assert that the Python version as written to pythonversion.txt in the CIBW_BEFORE_BUILD step # assert that the Python version as written to pythonversion.txt in the CIBW_BEFORE_BUILD step
# is the same one as is currently running. # is the same one as is currently running.
version_file = ( version_file = 'c:\\pythonversion.txt' if sys.platform == 'win32' else '/tmp/pythonversion.txt'
"c:\\pythonversion.txt" if sys.platform == "win32" else "/tmp/pythonversion.txt"
)
with open(version_file) as f: with open(version_file) as f:
stored_version = f.read() stored_version = f.read()
print("stored_version", stored_version) print('stored_version', stored_version)
print("sys.version", sys.version) print('sys.version', sys.version)
assert stored_version == sys.version assert stored_version == sys.version
# check that the executable also was written # check that the executable also was written
executable_file = ( executable_file = 'c:\\pythonexecutable.txt' if sys.platform == 'win32' else '/tmp/pythonexecutable.txt'
"c:\\pythonexecutable.txt" if sys.platform == "win32" else "/tmp/pythonexecutable.txt"
)
with open(executable_file) as f: with open(executable_file) as f:
stored_executable = f.read() stored_executable = f.read()
print("stored_executable", stored_executable) print('stored_executable', stored_executable)
print("sys.executable", sys.executable) print('sys.executable', sys.executable)
# windows/mac are case insensitive # windows/mac are case insensitive
assert ( assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower()
os.path.realpath(stored_executable).lower()
== os.path.realpath(sys.executable).lower()
)
''') ''')
) )
@@ -40,16 +33,13 @@ def test(tmpdir):
project_with_before_build_asserts.generate(project_dir) project_with_before_build_asserts.generate(project_dir)
# build the wheels # build the wheels
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, # write python version information to a temporary file, this is
add_env={ # checked in setup.py
# write python version information to a temporary file, this is '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)"''',
# checked in setup.py '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)"''',
"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 # also check that we got the right wheels
expected_wheels = utils.expected_wheels("spam", "0.1.0") expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
+9 -11
View File
@@ -5,11 +5,11 @@ from .template_projects import CTemplateProject
project_with_skip_asserts = CTemplateProject( project_with_skip_asserts = CTemplateProject(
setup_py_add=textwrap.dedent(r''' setup_py_add=textwrap.dedent(r'''
# explode if run on Python 2.7 or Python 3.4 (these should be skipped) # explode if run on Python 2.7 or Python 3.7 (these should be skipped)
if sys.version_info[0:2] == (2, 7): if sys.version_info[0:2] == (2, 7):
raise Exception("Python 2.7 should not be built") raise Exception("Python 2.7 should not be built")
if sys.version_info[0:2] == (3, 4): if sys.version_info[0:2] == (3, 7):
raise Exception("Python 3.4 should be skipped") raise Exception("Python 3.7 should be skipped")
''') ''')
) )
@@ -18,14 +18,12 @@ def test(tmpdir):
project_with_skip_asserts.generate(project_dir) project_with_skip_asserts.generate(project_dir)
# build the wheels # build the wheels
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, add_env={"CIBW_BUILD": "cp3?-*", "CIBW_SKIP": "cp37-*",} 'CIBW_BUILD': 'cp3?-*',
) 'CIBW_SKIP': 'cp37-*',
})
# check that we got the right wheels. There should be no 2.7 or 3.7. # check that we got the right wheels. There should be no 2.7 or 3.7.
expected_wheels = [ expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
w if ('-cp3' in w) and ('-cp37' not in w)]
for w in utils.expected_wheels("spam", "0.1.0")
if ("-cp3" in w) and ("-cp37" not in w)
]
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
+24 -10
View File
@@ -1,4 +1,7 @@
import os, inspect, textwrap import os
import pytest
import subprocess
import textwrap
from . import utils from . import utils
from .template_projects import CTemplateProject from .template_projects import CTemplateProject
@@ -30,15 +33,26 @@ def test(tmpdir):
# write some information into the CIBW_ENVIRONMENT, for expansion and # write some information into the CIBW_ENVIRONMENT, for expansion and
# insertion into the environment by cibuildwheel. This is checked # insertion into the environment by cibuildwheel. This is checked
# in setup_py_add # in setup.py
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, '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''',
add_env={ '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"''',
"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 # also check that we got the right wheels built
expected_wheels = utils.expected_wheels("spam", "0.1.0") expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
def test_overridden_path(tmp_path):
project_dir = str(tmp_path / 'project')
output_dir = str(tmp_path / 'output')
CTemplateProject().generate(project_dir)
# mess up PATH, somehow
with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run(project_dir, output_dir=output_dir, add_env={
'CIBW_ENVIRONMENT': '''SOMETHING="$(mkdir new_path && touch new_path/python)" PATH="$(realpath new_path):$PATH"''',
'CIBW_ENVIRONMENT_WINDOWS': '''SOMETHING="$(mkdir new_path && type nul > new_path/python.exe)" PATH="$CD\\new_path;$PATH"''',
})
assert len(os.listdir(output_dir)) == 0
+11 -16
View File
@@ -17,26 +17,21 @@ dockcross_only_project = CTemplateProject(
) )
def test(tmpdir): def test(tmpdir):
if utils.platform != "linux": if utils.platform != 'linux':
pytest.skip("the test is only relevant to the linux build") pytest.skip('the test is only relevant to the linux build')
if platform.machine() not in ['x86_64', 'i686']:
pytest.skip('this test is currently only possible on x86_64/i686 due to availability of alternative images')
project_dir = str(tmpdir) project_dir = str(tmpdir)
dockcross_only_project.generate(project_dir) dockcross_only_project.generate(project_dir)
actual_wheels = utils.cibuildwheel_run( actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
project_dir, 'CIBW_MANYLINUX_X86_64_IMAGE': 'dockcross/manylinux2010-x64',
add_env={ 'CIBW_MANYLINUX_I686_IMAGE': 'dockcross/manylinux2010-x86',
"CIBW_MANYLINUX_X86_64_IMAGE": "dockcross/manylinux2010-x64", 'CIBW_SKIP': 'pp*',
"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
"CIBW_ENVIRONMENT": 'AUDITWHEEL_PLAT=`if [ $(uname -i) == "x86_64" ]; then echo "manylinux2010_x86_64"; else echo "manylinux1_i686"; fi`',
},
)
# also check that we got the right wheels built # also check that we got the right wheels built
expected_wheels = [ expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0')
w if '-pp' not in w]
for w in utils.expected_wheels("spam", "0.1.0")
if "-manylinux2010_i686" not in w
]
assert set(actual_wheels) == set(expected_wheels) assert set(actual_wheels) == set(expected_wheels)
+4 -20
View File
@@ -7,14 +7,13 @@ from . import utils
from .template_projects import SetuptoolsTemplateProject from .template_projects import SetuptoolsTemplateProject
import jinja2 import jinja2
# TODO: specify these at runtime according to manylinux_image
cpp_project = SetuptoolsTemplateProject( cpp_project = SetuptoolsTemplateProject(
setup_py_add='''ext_modules=[Extension('spam', sources=['spam.cpp'])],''' setup_py_add='''ext_modules=[Extension('spam', sources=['spam.cpp'])],'''
) )
cpp_project.files['spam.cpp'] = jinja2.Template(r''' cpp_project.files['spam.cpp'] = jinja2.Template(r'''
#include <Python.h> #include <Python.h>
{{ spam_cpp_add }} {{ spam_cpp_top_level_add }}
static PyObject * static PyObject *
spam_system(PyObject *self, PyObject *args) spam_system(PyObject *self, PyObject *args)
@@ -64,28 +63,13 @@ MOD_INIT(spam)
} }
''') ''')
spam_cpp_top_level_add = '''
// Depending on the requested standard, use a modern C++ feature
// that was introduced in that standard.
#if STANDARD == 11
#include <array>
#elif STANDARD == 14
int a = 100'000;
#elif STANDARD == 17
#include <utility>
auto a = std::pair(5.0, false);
#else
#error Standard needed
#endif
'''
project_dir = os.path.dirname(__file__) project_dir = os.path.dirname(__file__)
def test_cpp11(tmpdir): def test_cpp11(tmpdir):
# This test checks that the C++11 standard is supported # This test checks that the C++11 standard is supported
project_dir = str(tmpdir) project_dir = str(tmpdir)
cpp_project.template_context['spam_cpp_add'] = '#include <array>' cpp_project.template_context['spam_cpp_top_level_add'] = '#include <array>'
cpp_project.generate(project_dir) cpp_project.generate(project_dir)
# VC++ for Python 2.7 does not support modern standards # VC++ for Python 2.7 does not support modern standards
@@ -102,7 +86,7 @@ def test_cpp14(tmpdir):
# This test checks that the C++14 standard is supported # This test checks that the C++14 standard is supported
project_dir = str(tmpdir) project_dir = str(tmpdir)
cpp_project.template_context['spam_cpp_add'] = "int a = 100'000;" cpp_project.template_context['spam_cpp_top_level_add'] = "int a = 100'000;"
cpp_project.generate(project_dir) cpp_project.generate(project_dir)
# VC++ for Python 2.7 does not support modern standards # VC++ for Python 2.7 does not support modern standards
@@ -123,7 +107,7 @@ def test_cpp17(tmpdir):
# This test checks that the C++17 standard is supported # This test checks that the C++17 standard is supported
project_dir = str(tmpdir) project_dir = str(tmpdir)
cpp_project.template_context['spam_cpp_add'] = textwrap.dedent(''' cpp_project.template_context['spam_cpp_top_level_add'] = textwrap.dedent('''
#include <utility> #include <utility>
auto a = std::pair(5.0, false); auto a = std::pair(5.0, false);
''') ''')
+1 -1
View File
@@ -1,5 +1,5 @@
import os import os
import utils from . import utils
from test.template_projects.c import CTemplateProject from test.template_projects.c import CTemplateProject
before_test_project = CTemplateProject() before_test_project = CTemplateProject()
+2 -3
View File
@@ -1,5 +1,5 @@
import os import os
import utils from . import utils
from .template_projects.c import spam_c_template from .template_projects.c import spam_c_template
from .template_projects import TemplateProject from .template_projects import TemplateProject
@@ -35,8 +35,7 @@ def test(capfd, tmpdir):
actual_wheels = utils.cibuildwheel_run(project_dir, package_dir=package_dir, add_env={ actual_wheels = utils.cibuildwheel_run(project_dir, package_dir=package_dir, add_env={
'CIBW_BEFORE_BUILD': 'python {project}/bin/before_build.py', 'CIBW_BEFORE_BUILD': 'python {project}/bin/before_build.py',
'CIBW_TEST_COMMAND': 'python {package}/test/run_tests.py', 'CIBW_TEST_COMMAND': 'python {package}/test/run_tests.py',
# this shouldn't depend on the version of python, so build only # this shouldn't depend on the version of python, so build only CPython 3.6
# CPython 3.6
'CIBW_BUILD': 'cp36-*', 'CIBW_BUILD': 'cp36-*',
}) })