2020-07-21 18:41:51 +02:00
|
|
|
import subprocess
|
2020-05-02 22:50:52 +01:00
|
|
|
import textwrap
|
|
|
|
|
|
2021-01-06 13:50:58 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from . import test_projects, utils
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
project_with_before_build_asserts = test_projects.new_c_project(
|
2020-05-02 16:54:19 +01:00
|
|
|
setup_py_add=textwrap.dedent(r'''
|
2021-02-18 08:15:37 +01:00
|
|
|
import os
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
# assert that the Python version as written to pythonversion.txt in the CIBW_BEFORE_BUILD step
|
|
|
|
|
# is the same one as is currently running.
|
2020-05-02 22:42:35 +01:00
|
|
|
version_file = 'c:\\pythonversion.txt' if sys.platform == 'win32' else '/tmp/pythonversion.txt'
|
2020-05-02 16:54:19 +01:00
|
|
|
with open(version_file) as f:
|
|
|
|
|
stored_version = f.read()
|
2020-05-02 22:42:35 +01:00
|
|
|
print('stored_version', stored_version)
|
|
|
|
|
print('sys.version', sys.version)
|
2020-05-02 16:54:19 +01:00
|
|
|
assert stored_version == sys.version
|
|
|
|
|
|
|
|
|
|
# check that the executable also was written
|
2020-05-02 22:42:35 +01:00
|
|
|
executable_file = 'c:\\pythonexecutable.txt' if sys.platform == 'win32' else '/tmp/pythonexecutable.txt'
|
2020-05-02 16:54:19 +01:00
|
|
|
with open(executable_file) as f:
|
|
|
|
|
stored_executable = f.read()
|
2020-05-02 22:42:35 +01:00
|
|
|
print('stored_executable', stored_executable)
|
|
|
|
|
print('sys.executable', sys.executable)
|
2020-05-02 16:54:19 +01:00
|
|
|
# windows/mac are case insensitive
|
2020-05-02 22:42:35 +01:00
|
|
|
assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower()
|
2020-05-02 16:54:19 +01:00
|
|
|
''')
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2020-05-03 14:08:57 +01:00
|
|
|
def test(tmp_path):
|
|
|
|
|
project_dir = tmp_path / 'project'
|
2020-05-02 16:54:19 +01:00
|
|
|
project_with_before_build_asserts.generate(project_dir)
|
|
|
|
|
|
2020-07-20 01:42:57 +02:00
|
|
|
before_build = ('''python -c "import sys; open('{output_dir}pythonversion.txt', 'w').write(sys.version)" && '''
|
2020-07-21 18:41:51 +02:00
|
|
|
'''python -c "import sys; open('{output_dir}pythonexecutable.txt', 'w').write(sys.executable)"''')
|
2020-07-20 00:46:36 +02:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
# build the wheels
|
2020-05-02 22:42:35 +01:00
|
|
|
actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
|
|
|
|
|
# write python version information to a temporary file, this is
|
|
|
|
|
# checked in setup.py
|
2020-07-20 01:42:57 +02:00
|
|
|
'CIBW_BEFORE_BUILD': before_build.format(output_dir='/tmp/'),
|
|
|
|
|
'CIBW_BEFORE_BUILD_WINDOWS': before_build.format(output_dir=r'c:\\'),
|
2020-05-02 22:42:35 +01:00
|
|
|
})
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
# also check that we got the right wheels
|
2020-05-02 22:42:35 +01:00
|
|
|
expected_wheels = utils.expected_wheels('spam', '0.1.0')
|
2020-05-02 16:54:19 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
2020-07-21 18:41:51 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_failing_command(tmp_path):
|
|
|
|
|
project_dir = tmp_path / 'project'
|
|
|
|
|
test_projects.new_c_project().generate(project_dir)
|
|
|
|
|
|
|
|
|
|
with pytest.raises(subprocess.CalledProcessError):
|
|
|
|
|
utils.cibuildwheel_run(project_dir, add_env={
|
|
|
|
|
'CIBW_BEFORE_BUILD': 'false',
|
|
|
|
|
'CIBW_BEFORE_BUILD_WINDOWS': 'exit /b 1',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cwd(tmp_path):
|
|
|
|
|
project_dir = tmp_path / 'project'
|
|
|
|
|
test_projects.new_c_project().generate(project_dir)
|
|
|
|
|
|
|
|
|
|
actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
|
|
|
|
|
'CIBW_BEFORE_BUILD': f'''python -c "import os; assert os.getcwd() == {str(project_dir)!r}"''',
|
|
|
|
|
'CIBW_BEFORE_BUILD_LINUX': '''python -c "import os; assert os.getcwd() == '/project'"''',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expected_wheels = utils.expected_wheels('spam', '0.1.0')
|
|
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|