refactor: Override options redesign
* Add test for defaults, fix platform detection * Improve correctness of reader.identifier with block * Fix options test to be multiplatform * 'Refactored by Sourcery' docs: write a section on overrides tests: test docker launches feat: add identifiers to launches test: add test for correct build step generation Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -15,9 +15,6 @@ class ArgsInterceptor:
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
MOCK_PACKAGE_DIR = Path("some_package_dir")
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_protection(monkeypatch):
|
||||
"""
|
||||
@@ -41,22 +38,8 @@ def mock_protection(monkeypatch):
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fake_package_dir(monkeypatch):
|
||||
"""
|
||||
Monkey-patch enough for the main() function to run
|
||||
"""
|
||||
real_path_exists = Path.exists
|
||||
|
||||
def mock_path_exists(path):
|
||||
if path == MOCK_PACKAGE_DIR / "setup.py":
|
||||
return True
|
||||
else:
|
||||
return real_path_exists(path)
|
||||
|
||||
args = ["cibuildwheel", str(MOCK_PACKAGE_DIR)]
|
||||
monkeypatch.setattr(Path, "exists", mock_path_exists)
|
||||
monkeypatch.setattr(sys, "argv", args)
|
||||
return args
|
||||
def fake_package_dir_autouse(fake_package_dir):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
||||
@@ -3,10 +3,12 @@ from fnmatch import fnmatch
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
import tomli
|
||||
|
||||
from cibuildwheel.__main__ import main
|
||||
from cibuildwheel.environment import ParsedEnvironment
|
||||
from cibuildwheel.util import BuildSelector
|
||||
from cibuildwheel.options import BuildOptions, _get_pinned_docker_images
|
||||
from cibuildwheel.util import BuildSelector, resources_dir
|
||||
|
||||
# CIBW_PLATFORM is tested in main_platform_test.py
|
||||
|
||||
@@ -18,13 +20,13 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].globals.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_output_dir_default(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == Path("wheelhouse")
|
||||
assert intercepted_build_args.args[0].globals.output_dir == Path("wheelhouse")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("also_set_environment", [False, True])
|
||||
@@ -37,7 +39,7 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.output_dir == OUTPUT_DIR
|
||||
assert intercepted_build_args.args[0].globals.output_dir == OUTPUT_DIR
|
||||
|
||||
|
||||
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty):
|
||||
@@ -49,7 +51,7 @@ def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_emp
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].general_build_options.build_selector
|
||||
intercepted_build_selector = intercepted_build_args.args[0].globals.build_selector
|
||||
assert isinstance(intercepted_build_selector, BuildSelector)
|
||||
assert intercepted_build_selector("build24-this")
|
||||
assert not intercepted_build_selector("skip65-that")
|
||||
@@ -97,13 +99,15 @@ def test_manylinux_images(
|
||||
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
if platform == "linux":
|
||||
assert fnmatch(
|
||||
intercepted_build_args.args[0].general_build_options.manylinux_images[architecture],
|
||||
build_options.manylinux_images[architecture],
|
||||
full_image,
|
||||
)
|
||||
else:
|
||||
assert intercepted_build_args.args[0].general_build_options.manylinux_images is None
|
||||
assert build_options.manylinux_images is None
|
||||
|
||||
|
||||
def get_default_repair_command(platform):
|
||||
@@ -131,8 +135,10 @@ def test_repair_command(
|
||||
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
expected_repair = repair_command or get_default_repair_command(platform)
|
||||
assert intercepted_build_args.args[0].general_build_options.repair_command == expected_repair
|
||||
assert build_options.repair_command == expected_repair
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -150,7 +156,9 @@ def test_environment(environment, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
intercepted_environment = intercepted_build_args.args[0].general_build_options.environment
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
intercepted_environment = build_options.environment
|
||||
|
||||
assert isinstance(intercepted_environment, ParsedEnvironment)
|
||||
assert intercepted_environment.as_dictionary(prev_environment={}) == environment
|
||||
|
||||
@@ -169,10 +177,9 @@ def test_test_requires(
|
||||
|
||||
main()
|
||||
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.test_requires
|
||||
== (test_requires or "").split()
|
||||
)
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_requires == (test_requires or "").split()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_extras", [None, "extras"])
|
||||
@@ -187,9 +194,9 @@ def test_test_extras(test_extras, platform_specific, platform, intercepted_build
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.test_extras == (
|
||||
"[" + test_extras + "]" if test_extras else ""
|
||||
)
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_extras == ("[" + test_extras + "]" if test_extras else "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_command", [None, "test --command"])
|
||||
@@ -206,7 +213,9 @@ def test_test_command(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.test_command == (test_command or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.test_command == (test_command or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("before_build", [None, "before --build"])
|
||||
@@ -223,7 +232,8 @@ def test_before_build(
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.before_build == (before_build or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
assert build_options.before_build == (before_build or "")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("build_verbosity", [None, 0, 2, -2, 4, -4])
|
||||
@@ -239,11 +249,10 @@ def test_build_verbosity(
|
||||
monkeypatch.setenv("CIBW_BUILD_VERBOSITY", str(build_verbosity))
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
expected_verbosity = max(-3, min(3, int(build_verbosity or 0)))
|
||||
assert (
|
||||
intercepted_build_args.args[0].general_build_options.build_verbosity == expected_verbosity
|
||||
)
|
||||
assert build_options.build_verbosity == expected_verbosity
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -294,4 +303,36 @@ def test_before_all(before_all, platform_specific, platform, intercepted_build_a
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].general_build_options.before_all == (before_all or "")
|
||||
build_options = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
|
||||
assert build_options.before_all == (before_all or "")
|
||||
|
||||
|
||||
def test_defaults(platform, intercepted_build_args):
|
||||
main()
|
||||
|
||||
build_options: BuildOptions = intercepted_build_args.args[0].build_options(identifier=None)
|
||||
defaults_config_path = resources_dir / "defaults.toml"
|
||||
with defaults_config_path.open("rb") as f:
|
||||
defaults_toml = tomli.load(f)
|
||||
|
||||
root_defaults = defaults_toml["tool"]["cibuildwheel"]
|
||||
platform_defaults = defaults_toml["tool"]["cibuildwheel"][platform]
|
||||
|
||||
defaults = {}
|
||||
defaults.update(root_defaults)
|
||||
defaults.update(platform_defaults)
|
||||
|
||||
# test a few options
|
||||
assert build_options.before_all == defaults["before-all"]
|
||||
repair_wheel_default = defaults["repair-wheel-command"]
|
||||
if isinstance(repair_wheel_default, list):
|
||||
repair_wheel_default = " && ".join(repair_wheel_default)
|
||||
assert build_options.repair_command == repair_wheel_default
|
||||
assert build_options.build_frontend == defaults["build-frontend"]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.manylinux_images
|
||||
pinned_images = _get_pinned_docker_images()
|
||||
default_x86_64_image = pinned_images["x86_64"][defaults["manylinux-x86_64-image"]]
|
||||
assert build_options.manylinux_images["x86_64"] == default_x86_64_image
|
||||
|
||||
@@ -5,7 +5,7 @@ import pytest
|
||||
from cibuildwheel.__main__ import main
|
||||
from cibuildwheel.architecture import Architecture
|
||||
|
||||
from .conftest import MOCK_PACKAGE_DIR
|
||||
from ..conftest import MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_unknown_platform_non_ci(monkeypatch, capsys):
|
||||
@@ -58,26 +58,29 @@ def test_platform_argument(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
assert options.globals.package_dir == MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_platform_environment(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
||||
assert options.globals.package_dir == MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_archs_default(platform, intercepted_build_args, monkeypatch):
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.x86_64, Architecture.i686}
|
||||
assert options.globals.architectures == {Architecture.x86_64, Architecture.i686}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64, Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.AMD64, Architecture.x86}
|
||||
else:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("use_env_var", [False, True])
|
||||
@@ -96,8 +99,8 @@ def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_v
|
||||
|
||||
else:
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
assert build_options.architectures == {Architecture.ppc64le}
|
||||
options = intercepted_build_args.args[0]
|
||||
assert options.globals.architectures == {Architecture.ppc64le}
|
||||
|
||||
|
||||
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
|
||||
@@ -107,38 +110,38 @@ def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS_MACOS", "x86_64")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.ppc64le}
|
||||
assert options.globals.architectures == {Architecture.ppc64le}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.x86}
|
||||
elif platform == "macos":
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
|
||||
|
||||
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "native")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform in {"linux", "macos"}:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.AMD64}
|
||||
|
||||
|
||||
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "auto64")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform in {"linux", "macos"}:
|
||||
assert build_options.architectures == {Architecture.x86_64}
|
||||
assert options.globals.architectures == {Architecture.x86_64}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.AMD64}
|
||||
|
||||
|
||||
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
|
||||
@@ -152,22 +155,22 @@ def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
|
||||
else:
|
||||
main()
|
||||
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {Architecture.i686}
|
||||
assert options.globals.architectures == {Architecture.i686}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86}
|
||||
assert options.globals.architectures == {Architecture.x86}
|
||||
|
||||
|
||||
def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setenv("CIBW_ARCHS", "all")
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == "linux":
|
||||
assert build_options.architectures == {
|
||||
assert options.globals.architectures == {
|
||||
Architecture.x86_64,
|
||||
Architecture.i686,
|
||||
Architecture.aarch64,
|
||||
@@ -175,9 +178,9 @@ def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
|
||||
Architecture.s390x,
|
||||
}
|
||||
elif platform == "windows":
|
||||
assert build_options.architectures == {Architecture.x86, Architecture.AMD64}
|
||||
assert options.globals.architectures == {Architecture.x86, Architecture.AMD64}
|
||||
elif platform == "macos":
|
||||
assert build_options.architectures == {
|
||||
assert options.globals.architectures == {
|
||||
Architecture.x86_64,
|
||||
Architecture.arm64,
|
||||
Architecture.universal2,
|
||||
|
||||
@@ -27,7 +27,8 @@ def test_no_override(platform, monkeypatch, intercepted_build_args):
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector("cp39-win32")
|
||||
assert intercepted_build_selector("cp36-win32")
|
||||
@@ -40,7 +41,8 @@ def test_override_env(platform, monkeypatch, intercepted_build_args):
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -61,7 +63,8 @@ def test_override_setup_cfg(platform, monkeypatch, intercepted_build_args, fake_
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -82,7 +85,8 @@ def test_override_pyproject_toml(platform, monkeypatch, intercepted_build_args,
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
|
||||
|
||||
@@ -107,7 +111,8 @@ def test_override_setup_py_simple(platform, monkeypatch, intercepted_build_args,
|
||||
|
||||
main()
|
||||
|
||||
intercepted_build_selector = intercepted_build_args.args[0].build_selector
|
||||
options = intercepted_build_args.args[0]
|
||||
intercepted_build_selector = options.globals.build_selector
|
||||
|
||||
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.7")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user