Files
cibuildwheel/test/test_emulation.py
T

73 lines
2.1 KiB
Python
Raw Normal View History

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.filter("spam") == 0
assert spam.filter("ham") != 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,
2025-04-28 18:05:03 +02:00
# TODO remove me once proper support is added
2025-05-12 18:54:02 +02:00
"CIBW_MANYLINUX_RISCV64_IMAGE": "ghcr.io/mayeut/manylinux_2_35:2025.05.11-1",
2025-04-28 18:05:03 +02:00
"CIBW_SKIP": "*-musllinux_riscv64",
2021-04-30 17:56:34 -04:00
},
)
2020-12-21 11:06:25 +00:00
# also check that we got the right wheels
2025-04-28 18:05:03 +02:00
expected_wheels = list(
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
)
2025-04-28 18:05:03 +02:00
# TODO remove me once proper support is added
expected_wheels = [wheel for wheel in expected_wheels if "musllinux_1_2_riscv64" not in wheel]
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):
2025-05-16 11:11:16 +01:00
if utils.get_platform() == "linux":
2021-05-03 11:45:43 -04:00
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