Files
cibuildwheel/test/test_emulation.py
T

68 lines
1.8 KiB
Python
Raw Normal View History

from __future__ import annotations
import itertools
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()
2023-10-27 01:21:20 -04:00
project_with_a_test.files["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):
archs = request.config.getoption("--run-emulation")
if archs is None:
2022-06-27 19:08:46 +01:00
pytest.skip("needs --run-emulation option to run")
if archs == "all":
archs = " ".join(utils.EMULATED_ARCHS)
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": archs,
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 = itertools.chain.from_iterable(
utils.expected_wheels("spam", "0.1.0", machine_arch=arch, single_arch=True)
for arch in archs.split(" ")
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