Files
cibuildwheel/unit_test/main_tests/main_platform_test.py
T

265 lines
8.2 KiB
Python
Raw Normal View History

from __future__ import annotations
2019-12-15 20:28:38 +01:00
import sys
import pytest
2019-12-15 20:28:38 +01:00
from cibuildwheel.__main__ import main
2021-01-31 17:14:15 -05:00
from cibuildwheel.architecture import Architecture
2021-10-12 02:05:47 +01:00
from ..conftest import MOCK_PACKAGE_DIR
2019-12-15 20:28:38 +01:00
def test_unknown_platform_non_ci(monkeypatch, capsys):
2021-05-03 11:45:43 -04:00
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("BITRISE_BUILD_NUMBER", raising=False)
monkeypatch.delenv("AZURE_HTTP_USER_AGENT", raising=False)
monkeypatch.delenv("TRAVIS", raising=False)
monkeypatch.delenv("APPVEYOR", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("GITLAB_CI", raising=False)
monkeypatch.delenv("CIRCLECI", raising=False)
2022-07-24 01:17:22 +02:00
monkeypatch.delenv("CIRRUS_CI", raising=False)
2021-05-03 11:45:43 -04:00
monkeypatch.delenv("CIBW_PLATFORM", raising=False)
2019-12-15 20:28:38 +01:00
with pytest.raises(SystemExit) as exit:
main()
2023-01-30 15:53:44 -05:00
assert exit.value.code == 2
2019-12-15 20:28:38 +01:00
_, err = capsys.readouterr()
2021-05-03 11:45:43 -04:00
assert "cibuildwheel: Unable to detect platform." in err
assert "cibuildwheel should run on your CI server" in err
2019-12-15 20:28:38 +01:00
def test_unknown_platform_on_ci(monkeypatch, capsys):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CI", "true")
monkeypatch.setattr(sys, "platform", "nonexistent")
monkeypatch.delenv("CIBW_PLATFORM", raising=False)
2019-12-15 20:28:38 +01:00
with pytest.raises(SystemExit) as exit:
main()
2023-01-30 15:53:44 -05:00
assert exit.value.code == 2
2019-12-15 20:28:38 +01:00
_, err = capsys.readouterr()
assert 'cibuildwheel: Unable to detect platform from "sys.platform"' in err
def test_unknown_platform(monkeypatch, capsys):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
2019-12-15 20:28:38 +01:00
with pytest.raises(SystemExit) as exit:
main()
_, err = capsys.readouterr()
assert exit.value.code == 2
2021-05-03 11:45:43 -04:00
assert "cibuildwheel: Unsupported platform: nonexistent" in err
2019-12-15 20:28:38 +01:00
def test_platform_argument(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
2023-01-30 15:53:44 -05:00
monkeypatch.setattr(sys, "argv", [*sys.argv, "--platform", platform])
2019-12-15 20:28:38 +01:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2022-04-26 22:21:27 -04:00
assert options.globals.package_dir == MOCK_PACKAGE_DIR.resolve()
2019-12-15 20:28:38 +01:00
2023-01-30 15:53:44 -05:00
@pytest.mark.usefixtures("platform")
def test_platform_environment(intercepted_build_args):
2019-12-15 20:28:38 +01:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2019-12-15 20:28:38 +01:00
2022-04-26 22:21:27 -04:00
assert options.globals.package_dir == MOCK_PACKAGE_DIR.resolve()
2020-12-21 11:00:33 +00:00
2023-01-30 15:53:44 -05:00
def test_archs_default(platform, intercepted_build_args):
2020-12-21 11:00:33 +00:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2020-12-21 11:00:33 +00:00
2021-05-03 11:45:43 -04:00
if platform == "linux":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86_64, Architecture.i686}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.AMD64, Architecture.x86}
2020-12-21 11:00:33 +00:00
else:
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86_64}
2020-12-21 11:00:33 +00:00
2021-05-03 11:45:43 -04:00
@pytest.mark.parametrize("use_env_var", [False, True])
2020-12-21 11:00:33 +00:00
def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var):
if use_env_var:
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "ppc64le")
2020-12-21 11:00:33 +00:00
else:
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "unused")
2023-01-30 15:53:44 -05:00
monkeypatch.setattr(sys, "argv", [*sys.argv, "--archs", "ppc64le"])
2020-12-21 11:00:33 +00:00
2021-05-03 11:45:43 -04:00
if platform in {"macos", "windows"}:
2021-01-22 09:33:22 -05:00
with pytest.raises(SystemExit) as exit:
2021-01-22 09:23:52 -05:00
main()
2021-01-22 09:33:22 -05:00
assert exit.value.args == (4,)
2020-12-21 11:00:33 +00:00
2021-01-22 09:23:52 -05:00
else:
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
assert options.globals.architectures == {Architecture.ppc64le}
2020-12-21 11:05:19 +00:00
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "unused")
monkeypatch.setenv("CIBW_ARCHS_LINUX", "ppc64le")
monkeypatch.setenv("CIBW_ARCHS_WINDOWS", "x86")
monkeypatch.setenv("CIBW_ARCHS_MACOS", "x86_64")
2020-12-21 11:05:19 +00:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2020-12-21 11:05:19 +00:00
2021-05-03 11:45:43 -04:00
if platform == "linux":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.ppc64le}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86}
2021-05-03 11:45:43 -04:00
elif platform == "macos":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86_64}
2021-01-15 09:38:47 -05:00
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "native")
2021-01-15 09:38:47 -05:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2021-01-15 09:38:47 -05:00
2021-05-03 11:45:43 -04:00
if platform in {"linux", "macos"}:
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86_64}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.AMD64}
2021-01-15 09:38:47 -05:00
2021-01-31 20:41:18 -05:00
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "auto64")
2021-01-31 20:41:18 -05:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2021-01-31 20:41:18 -05:00
2021-05-03 11:45:43 -04:00
if platform in {"linux", "macos"}:
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86_64}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.AMD64}
2021-01-31 20:41:18 -05:00
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "auto32")
2021-01-31 20:41:18 -05:00
2021-05-03 11:45:43 -04:00
if platform == "macos":
2021-01-31 20:41:18 -05:00
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.args == (4,)
else:
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2021-01-31 20:41:18 -05:00
2021-05-03 11:45:43 -04:00
if platform == "linux":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.i686}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {Architecture.x86}
2021-01-31 20:41:18 -05:00
2021-01-15 09:38:47 -05:00
def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
2021-05-03 11:45:43 -04:00
monkeypatch.setenv("CIBW_ARCHS", "all")
2021-01-15 09:38:47 -05:00
main()
2021-10-12 02:05:47 +01:00
options = intercepted_build_args.args[0]
2021-01-15 09:38:47 -05:00
2021-05-03 11:45:43 -04:00
if platform == "linux":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {
2021-04-30 17:56:34 -04:00
Architecture.x86_64,
Architecture.i686,
Architecture.aarch64,
Architecture.ppc64le,
Architecture.s390x,
}
2021-05-03 11:45:43 -04:00
elif platform == "windows":
assert options.globals.architectures == {
Architecture.x86,
Architecture.AMD64,
Architecture.ARM64,
}
2021-05-03 11:45:43 -04:00
elif platform == "macos":
2021-10-12 02:05:47 +01:00
assert options.globals.architectures == {
2021-04-30 17:56:34 -04:00
Architecture.x86_64,
Architecture.arm64,
Architecture.universal2,
}
2022-09-09 08:34:47 -04:00
@pytest.mark.parametrize(
2023-01-30 15:53:44 -05:00
("only", "plat"),
2022-09-09 08:34:47 -04:00
(
("cp311-manylinux_x86_64", "linux"),
("cp310-win_amd64", "windows"),
2022-09-24 23:10:05 +01:00
("cp310-win32", "windows"),
2022-09-09 08:34:47 -04:00
("cp311-macosx_x86_64", "macos"),
),
)
def test_only_argument(intercepted_build_args, monkeypatch, only, plat):
monkeypatch.setenv("CIBW_BUILD", "unused")
monkeypatch.setenv("CIBW_SKIP", "unused")
2023-01-30 15:53:44 -05:00
monkeypatch.setattr(sys, "argv", [*sys.argv, "--only", only])
2022-09-09 08:34:47 -04:00
main()
options = intercepted_build_args.args[0]
assert options.globals.build_selector.build_config == only
assert options.globals.build_selector.skip_config == ""
assert options.platform == plat
assert options.globals.architectures == Architecture.all_archs(plat)
@pytest.mark.parametrize("only", ("cp311-manylxinux_x86_64", "some_linux_thing"))
def test_only_failed(monkeypatch, only):
2023-01-30 15:53:44 -05:00
monkeypatch.setattr(sys, "argv", [*sys.argv, "--only", only])
2022-09-09 08:34:47 -04:00
with pytest.raises(SystemExit):
main()
def test_only_no_platform(monkeypatch):
monkeypatch.setattr(
2023-01-30 15:53:44 -05:00
sys, "argv", [*sys.argv, "--only", "cp311-manylinux_x86_64", "--platform", "macos"]
2022-09-09 08:34:47 -04:00
)
with pytest.raises(SystemExit):
main()
def test_only_no_archs(monkeypatch):
monkeypatch.setattr(
2023-01-30 15:53:44 -05:00
sys, "argv", [*sys.argv, "--only", "cp311-manylinux_x86_64", "--archs", "x86_64"]
2022-09-09 08:34:47 -04:00
)
with pytest.raises(SystemExit):
main()
@pytest.mark.parametrize(
2023-01-30 15:53:44 -05:00
("envvar_name", "envvar_value"),
2022-09-09 08:34:47 -04:00
(
("CIBW_BUILD", "cp310-*"),
("CIBW_SKIP", "cp311-*"),
("CIBW_ARCHS", "auto32"),
("CIBW_PLATFORM", "macos"),
),
)
def test_only_overrides_env_vars(monkeypatch, intercepted_build_args, envvar_name, envvar_value):
2023-01-30 15:53:44 -05:00
monkeypatch.setattr(sys, "argv", [*sys.argv, "--only", "cp311-manylinux_x86_64"])
2022-09-09 08:34:47 -04:00
monkeypatch.setenv(envvar_name, envvar_value)
main()
options = intercepted_build_args.args[0]
assert options.globals.build_selector.build_config == "cp311-manylinux_x86_64"
assert options.globals.build_selector.skip_config == ""
assert options.platform == "linux"
assert options.globals.architectures == Architecture.all_archs("linux")