Files
cibuildwheel/test/test_emulation.py
T

66 lines
1.8 KiB
Python
Raw Normal View History

from __future__ import annotations
import subprocess
2020-12-21 11:06:25 +00:00
2021-01-06 13:50:58 -05:00
import pytest
from . import test_projects, utils
2020-12-21 11:06:25 +00:00
project_with_a_test = test_projects.new_c_project()
2021-04-30 17:56:34 -04:00
project_with_a_test.files[
2021-05-03 11:45:43 -04:00
"test/spam_test.py"
] = r"""
2020-12-21 11:06:25 +00:00
import spam
def test_spam():
assert spam.system('python -c "exit(0)"') == 0
assert spam.system('python -c "exit(1)"') != 0
2021-05-03 11:45:43 -04:00
"""
2020-12-21 11:06:25 +00:00
2022-06-27 19:08:46 +01:00
def test(tmp_path, request):
if not request.config.getoption("--run-emulation"):
pytest.skip("needs --run-emulation option to run")
2021-05-03 11:45:43 -04:00
project_dir = tmp_path / "project"
2020-12-21 11:06:25 +00:00
project_with_a_test.generate(project_dir)
# build and test the wheels
2021-04-30 17:56:34 -04:00
actual_wheels = utils.cibuildwheel_run(
project_dir,
add_env={
2021-05-03 11:45:43 -04:00
"CIBW_TEST_REQUIRES": "pytest",
"CIBW_TEST_COMMAND": "pytest {project}/test",
"CIBW_ARCHS": "aarch64 ppc64le s390x",
2021-04-30 17:56:34 -04:00
},
)
2020-12-21 11:06:25 +00:00
# also check that we got the right wheels
expected_wheels = (
2021-05-03 11:45:43 -04:00
utils.expected_wheels("spam", "0.1.0", machine_arch="aarch64")
+ utils.expected_wheels("spam", "0.1.0", machine_arch="ppc64le")
+ utils.expected_wheels("spam", "0.1.0", machine_arch="s390x")
2020-12-21 11:06:25 +00:00
)
assert set(actual_wheels) == set(expected_wheels)
def test_setting_arch_on_other_platforms(tmp_path, capfd):
2021-05-03 11:45:43 -04:00
if utils.platform == "linux":
pytest.skip("this test checks the behaviour on platforms other than linux")
2021-05-03 11:45:43 -04:00
project_dir = tmp_path / "project"
project_with_a_test.generate(project_dir)
# build and test the wheels
with pytest.raises(subprocess.CalledProcessError):
2021-04-30 17:56:34 -04:00
utils.cibuildwheel_run(
project_dir,
add_env={
2021-05-03 11:45:43 -04:00
"CIBW_ARCHS": "aarch64",
2021-04-30 17:56:34 -04:00
},
)
captured = capfd.readouterr()
assert "Invalid archs option" in captured.err