2020-11-14 14:50:29 +00:00
|
|
|
import textwrap
|
2021-01-06 13:50:58 -05:00
|
|
|
|
2025-05-28 19:42:00 -04:00
|
|
|
import packaging.utils
|
2020-11-14 14:50:29 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from cibuildwheel.logger import Logger
|
2025-05-08 12:27:05 +01:00
|
|
|
from cibuildwheel.selector import EnableGroup
|
2021-01-06 13:50:58 -05:00
|
|
|
|
2020-11-14 14:50:29 +00:00
|
|
|
from . import test_projects, utils
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
basic_project = test_projects.new_c_project(
|
2021-04-30 17:56:34 -04:00
|
|
|
setup_py_add=textwrap.dedent(
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2020-05-02 16:54:19 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
if os.environ.get("CIBUILDWHEEL", "0") != "1":
|
|
|
|
|
raise Exception("CIBUILDWHEEL environment variable is not set to 1")
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2020-05-02 16:54:19 +01:00
|
|
|
)
|
|
|
|
|
|
2020-05-02 22:50:52 +01:00
|
|
|
|
2025-03-28 22:33:51 +08:00
|
|
|
@pytest.mark.serial
|
|
|
|
|
def test_dummy_serial():
|
|
|
|
|
"""A no-op test to ensure that at least one serial test is always found.
|
|
|
|
|
|
|
|
|
|
Without this no-op test, CI fails on CircleCI because no serial tests are
|
|
|
|
|
found, and pytest errors if a test suite finds no tests.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
2022-10-26 09:36:53 -04:00
|
|
|
def test(tmp_path, build_frontend_env, capfd):
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-11-14 14:28:47 +00:00
|
|
|
basic_project.generate(project_dir)
|
|
|
|
|
|
|
|
|
|
# build the wheels
|
2021-06-23 10:47:18 -04:00
|
|
|
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=build_frontend_env)
|
2020-11-14 14:28:47 +00:00
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2021-05-03 11:45:43 -04:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
2025-05-28 19:42:00 -04:00
|
|
|
actual_wheels_normalized = {packaging.utils.parse_wheel_filename(w) for w in actual_wheels}
|
|
|
|
|
expected_wheels_normalized = {packaging.utils.parse_wheel_filename(w) for w in expected_wheels}
|
|
|
|
|
assert actual_wheels_normalized == expected_wheels_normalized
|
2020-11-14 14:28:47 +00:00
|
|
|
|
2025-05-16 11:11:16 +01:00
|
|
|
enable_groups = utils.get_enable_groups()
|
2025-05-08 12:27:05 +01:00
|
|
|
if EnableGroup.GraalPy not in enable_groups:
|
|
|
|
|
# Verify pip warning not shown
|
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
|
for stream in (captured.err, captured.out):
|
|
|
|
|
assert "WARNING: Running pip as the 'root' user can result" not in stream
|
|
|
|
|
assert "A new release of pip available" not in stream
|
2022-10-26 09:36:53 -04:00
|
|
|
|
2020-11-14 14:28:47 +00:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
@pytest.mark.skip(reason="to keep test output clean")
|
2020-11-14 14:28:47 +00:00
|
|
|
def test_sample_build(tmp_path, capfd):
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 16:54:19 +01:00
|
|
|
basic_project.generate(project_dir)
|
|
|
|
|
|
2020-11-05 23:09:28 +00:00
|
|
|
# build the wheels, and let the output passthrough to the caller, so
|
|
|
|
|
# we can see how it looks
|
|
|
|
|
with capfd.disabled():
|
2020-11-13 15:22:43 +00:00
|
|
|
logger = Logger()
|
2021-05-03 11:45:43 -04:00
|
|
|
logger.step("test_sample_build")
|
2020-11-14 14:28:47 +00:00
|
|
|
try:
|
|
|
|
|
utils.cibuildwheel_run(project_dir)
|
|
|
|
|
finally:
|
|
|
|
|
logger.step_end()
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
|
2025-05-08 12:27:05 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"enable_setting", ["", "cpython-prerelease", "pypy", "cpython-freethreading"]
|
|
|
|
|
)
|
|
|
|
|
def test_build_identifiers(tmp_path, enable_setting, monkeypatch):
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 16:54:19 +01:00
|
|
|
basic_project.generate(project_dir)
|
|
|
|
|
|
2025-05-08 12:27:05 +01:00
|
|
|
monkeypatch.setenv("CIBW_ENABLE", enable_setting)
|
|
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
# check that the number of expected wheels matches the number of build
|
|
|
|
|
# identifiers
|
2021-04-03 16:59:10 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
2025-05-08 12:27:05 +01:00
|
|
|
build_identifiers = utils.cibuildwheel_get_build_identifiers(project_dir)
|
2025-01-20 11:17:01 +00:00
|
|
|
assert len(expected_wheels) == len(build_identifiers), (
|
|
|
|
|
f"{expected_wheels} vs {build_identifiers}"
|
|
|
|
|
)
|
2022-04-13 10:15:36 +01:00
|
|
|
|
|
|
|
|
|
2024-07-23 09:25:09 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
("add_args", "env_allow_empty"),
|
|
|
|
|
[
|
|
|
|
|
(["--allow-empty"], {}),
|
|
|
|
|
(["--allow-empty"], {"CIBW_ALLOW_EMPTY": "0"}),
|
|
|
|
|
(None, {"CIBW_ALLOW_EMPTY": "1"}),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
def test_allow_empty(tmp_path, add_args, env_allow_empty):
|
2022-04-13 10:15:36 +01:00
|
|
|
project_dir = tmp_path / "project"
|
|
|
|
|
basic_project.generate(project_dir)
|
|
|
|
|
|
|
|
|
|
# Sanity check - --allow-empty should cause a no-op build to complete
|
|
|
|
|
# without error
|
|
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
2022-04-14 10:21:21 +01:00
|
|
|
project_dir,
|
2025-03-24 16:58:47 +00:00
|
|
|
add_env={"CIBW_SKIP": "*", **env_allow_empty},
|
2024-07-23 09:25:09 +01:00
|
|
|
add_args=add_args,
|
2022-04-13 09:16:22 +00:00
|
|
|
)
|
2022-04-13 10:15:36 +01:00
|
|
|
|
2022-04-13 10:19:43 +01:00
|
|
|
# check that nothing was built
|
|
|
|
|
assert len(actual_wheels) == 0
|