def test_override_env(platform, monkeypatch, intercepted_build_args): monkeypatch.setenv("CIBW_PROJECT_REQUIRES_PYTHON", ">=3.8") main() options = intercepted_build_args.args[0] intercepted_build_selector = options.globals.build_selector assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8") assert intercepted_build_selector("cp39-win32") assert not intercepted_build_selector("cp36-win32")
def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch): env_string = ' '.join([f'{k}={v}' for k, v in environment.items()]) if platform_specific: monkeypatch.setenv('CIBW_ENVIRONMENT_' + platform.upper(), env_string) monkeypatch.setenv('CIBW_ENVIRONMENT', 'overwritten') else: monkeypatch.setenv('CIBW_ENVIRONMENT', env_string) main() intercepted_environment = intercepted_build_args.args[0].environment assert isinstance(intercepted_environment, ParsedEnvironment) assert intercepted_environment.as_dictionary(prev_environment={}) == environment
def test_output_dir_argument(also_set_environment, platform, intercepted_build_args, monkeypatch): OUTPUT_DIR = Path("some_output_dir") monkeypatch.setattr(sys, "argv", sys.argv + ["--output-dir", str(OUTPUT_DIR)]) if also_set_environment: monkeypatch.setenv("CIBW_OUTPUT_DIR", "not_this_output_dir") main() assert intercepted_build_args.args[ 0].globals.output_dir == OUTPUT_DIR.resolve()
def test_manylinux_images(architecture, image, full_image, platform, intercepted_build_args, monkeypatch): if image is not None: monkeypatch.setenv('CIBW_MANYLINUX_' + architecture.upper() + '_IMAGE', image) main() if platform == 'linux': assert intercepted_build_args.kwargs['manylinux_images'][ architecture] == full_image else: assert 'manylinux_images' not in intercepted_build_args.kwargs
def test_before_all(before_all, platform_specific, platform, intercepted_build_args, monkeypatch): if before_all is not None: if platform_specific: monkeypatch.setenv("CIBW_BEFORE_ALL_" + platform.upper(), before_all) monkeypatch.setenv("CIBW_BEFORE_ALL", "overwritten") else: monkeypatch.setenv("CIBW_BEFORE_ALL", before_all) main() build_options = intercepted_build_args.args[0].build_options(identifier=None) assert build_options.before_all == (before_all or "")
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty): BUILD = "some build* *-selector" SKIP = "some skip* *-selector" monkeypatch.setenv("CIBW_BUILD", BUILD) monkeypatch.setenv("CIBW_SKIP", SKIP) main() 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")
def test_build_selector(platform, intercepted_build_args, monkeypatch): BUILD = 'some build* *-selector' SKIP = 'some skip* *-selector' monkeypatch.setenv('CIBW_BUILD', BUILD) monkeypatch.setenv('CIBW_SKIP', SKIP) main() intercepted_build_selector = intercepted_build_args.args[0].build_selector assert isinstance(intercepted_build_selector, BuildSelector) assert intercepted_build_selector('build-this') assert not intercepted_build_selector('skip-that')
def test_unknown_platform_non_ci(monkeypatch, capsys): monkeypatch.delenv('CI', raising=False) monkeypatch.delenv('BITRISE_BUILD_NUMBER', raising=False) monkeypatch.delenv('AZURE_HTTP_USER_AGENT', raising=False) monkeypatch.delenv('GITHUB_WORKFLOW', raising=False) with pytest.raises(SystemExit) as exit: main() assert exit.value.code == 2 _, err = capsys.readouterr() assert 'cibuildwheel: Unable to detect platform.' in err assert 'cibuildwheel should run on your CI server' in err
def test_test_extras(test_extras, platform_specific, platform, intercepted_build_args, monkeypatch): if test_extras is not None: if platform_specific: monkeypatch.setenv("CIBW_TEST_EXTRAS_" + platform.upper(), test_extras) monkeypatch.setenv("CIBW_TEST_EXTRAS", "overwritten") else: monkeypatch.setenv("CIBW_TEST_EXTRAS", test_extras) main() build_options = intercepted_build_args.args[0].build_options(identifier=None) assert build_options.test_extras == ("[" + test_extras + "]" if test_extras else "")
def test_manylinux_images(architecture, image, full_image, platform, intercepted_build_args, monkeypatch): if image is not None: monkeypatch.setenv('CIBW_MANYLINUX_' + architecture.upper() + '_IMAGE', image) main() if platform == 'linux': assert fnmatch( intercepted_build_args.args[0].manylinux_images[architecture], full_image ) else: assert intercepted_build_args.args[0].manylinux_images is None
def test_unknown_platform(monkeypatch, capsys, tmp_path): monkeypatch.setattr(os, 'environ', {"CIBW_PLATFORM": "Something"}) monkeypatch.setattr(sys, "argv", ["python", str(tmp_path)]) apply_mock_protection(monkeypatch) with open(str(tmp_path / "setup.py"), "w") as f: f.write( 'from setuptools import setup\nsetup(name="spam", version="0.1.0",)' ) with pytest.raises(SystemExit) as exit: main() _, err = capsys.readouterr() assert exit.value.code == 2 assert 'cibuildwheel: Unsupported platform: Something' in err
def test_before_all(before_all, platform_specific, platform, intercepted_build_args, monkeypatch): if before_all is not None: if platform_specific: monkeypatch.setenv('CIBW_BEFORE_ALL_' + platform.upper(), before_all) monkeypatch.setenv('CIBW_BEFORE_ALL', 'overwritten') else: monkeypatch.setenv('CIBW_BEFORE_ALL', before_all) main() if before_all is None: before_all = "" assert intercepted_build_args.args[0].before_all == before_all
def test_test_requires(test_requires, platform_specific, platform, intercepted_build_args, monkeypatch): if test_requires is not None: if platform_specific: monkeypatch.setenv('CIBW_TEST_REQUIRES_' + platform.upper(), test_requires) monkeypatch.setenv('CIBW_TEST_REQUIRES', 'overwritten') else: monkeypatch.setenv('CIBW_TEST_REQUIRES', test_requires) main() assert intercepted_build_args.args[0].test_requires == (test_requires or '').split()
def test_repair_command(repair_command, platform_specific, platform, intercepted_build_args, monkeypatch): if repair_command is not None: if platform_specific: monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND_' + platform.upper(), repair_command) monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND', 'overwritten') else: monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND', repair_command) main() expected_repair = repair_command or get_default_repair_command(platform) assert intercepted_build_args.args[0].repair_command == expected_repair
def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch): env_string = " ".join(f"{k}={v}" for k, v in environment.items()) if platform_specific: monkeypatch.setenv("CIBW_ENVIRONMENT_" + platform.upper(), env_string) monkeypatch.setenv("CIBW_ENVIRONMENT", "overwritten") else: monkeypatch.setenv("CIBW_ENVIRONMENT", env_string) main() 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
def test_test_command( test_command, platform_specific, platform, intercepted_build_args, monkeypatch ): if test_command is not None: if platform_specific: monkeypatch.setenv("CIBW_TEST_COMMAND_" + platform.upper(), test_command) monkeypatch.setenv("CIBW_TEST_COMMAND", "overwritten") else: monkeypatch.setenv("CIBW_TEST_COMMAND", test_command) main() build_options = intercepted_build_args.args[0].build_options(identifier=None) assert build_options.test_command == (test_command or "")
def test_archs_default(platform, intercepted_build_args, monkeypatch): main() build_options = intercepted_build_args.args[0] if platform == 'linux': assert build_options.architectures == { Architecture.x86_64, Architecture.i686 } elif platform == 'windows': assert build_options.architectures == { Architecture.AMD64, Architecture.x86 } else: assert build_options.architectures == {Architecture.x86_64}
def test_build_verbosity( build_verbosity, platform_specific, platform, intercepted_build_args, monkeypatch ): if build_verbosity is not None: if platform_specific: monkeypatch.setenv("CIBW_BUILD_VERBOSITY_" + platform.upper(), str(build_verbosity)) monkeypatch.setenv("CIBW_BUILD_VERBOSITY", "overwritten") else: 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 build_options.build_verbosity == expected_verbosity
def test_override_pyproject_toml(platform, monkeypatch, intercepted_build_args, fake_package_dir): fake_package_dir.joinpath("pyproject.toml").write_text(textwrap.dedent(""" [project] requires-python = ">=3.8" """)) main() intercepted_build_selector = intercepted_build_args.args[0].build_selector assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8") assert intercepted_build_selector('cp39-win32') assert not intercepted_build_selector('cp36-win32')
def test_override_setup_cfg(platform, monkeypatch, intercepted_build_args, fake_package_dir): fake_package_dir.joinpath("setup.cfg").write_text(textwrap.dedent(""" [options] python_requires = >=3.8 """)) main() intercepted_build_selector = intercepted_build_args.args[0].build_selector assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8") assert intercepted_build_selector('cp39-win32') assert not intercepted_build_selector('cp36-win32')
def test_archs_default(platform, intercepted_build_args, monkeypatch): main() options = intercepted_build_args.args[0] if platform == "linux": assert options.globals.architectures == { Architecture.x86_64, Architecture.i686 } elif platform == "windows": assert options.globals.architectures == { Architecture.AMD64, Architecture.x86 } else: assert options.globals.architectures == {Architecture.x86_64}
def test_test_requires( test_requires, platform_specific, platform, intercepted_build_args, monkeypatch ): if test_requires is not None: if platform_specific: monkeypatch.setenv("CIBW_TEST_REQUIRES_" + platform.upper(), test_requires) monkeypatch.setenv("CIBW_TEST_REQUIRES", "overwritten") else: monkeypatch.setenv("CIBW_TEST_REQUIRES", test_requires) main() build_options = intercepted_build_args.args[0].build_options(identifier=None) assert build_options.test_requires == (test_requires or "").split()
def test_build_default_launches(mock_build_container, fake_package_dir, monkeypatch): monkeypatch.setattr(sys, "argv", sys.argv + ["--platform=linux"]) main() build_in_container = cast(mock.Mock, linux.build_in_container) assert build_in_container.call_count == 4 # In Python 3.8+, this can be simplified to [0].kwargs kwargs = build_in_container.call_args_list[0][1] assert "quay.io/pypa/manylinux2014_x86_64" in kwargs["container"]["image"] assert kwargs["container"]["cwd"] == PurePosixPath("/project") assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-manylinux_x86_64" for x in ALL_IDS} kwargs = build_in_container.call_args_list[1][1] assert "quay.io/pypa/manylinux2014_i686" in kwargs["container"]["image"] assert kwargs["container"]["cwd"] == PurePosixPath("/project") assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == {f"{x}-manylinux_i686" for x in ALL_IDS} kwargs = build_in_container.call_args_list[2][1] assert "quay.io/pypa/musllinux_1_1_x86_64" in kwargs["container"]["image"] assert kwargs["container"]["cwd"] == PurePosixPath("/project") assert not kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { f"{x}-musllinux_x86_64" for x in ALL_IDS for x in ALL_IDS if "pp" not in x } kwargs = build_in_container.call_args_list[3][1] assert "quay.io/pypa/musllinux_1_1_i686" in kwargs["container"]["image"] assert kwargs["container"]["cwd"] == PurePosixPath("/project") assert kwargs["container"]["simulate_32_bit"] identifiers = {x.identifier for x in kwargs["platform_configs"]} assert identifiers == { f"{x}-musllinux_i686" for x in ALL_IDS if "pp" not in x }
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch): monkeypatch.setenv('CIBW_ARCHS', 'unused') monkeypatch.setenv('CIBW_ARCHS_LINUX', 'ppc64le') monkeypatch.setenv('CIBW_ARCHS_WINDOWS', 'x86') monkeypatch.setenv('CIBW_ARCHS_MACOS', 'x86_64') main() build_options = intercepted_build_args.args[0] if platform == 'linux': assert build_options.architectures == {Architecture.ppc64le} elif platform == 'windows': assert build_options.architectures == {Architecture.x86} elif platform == 'macos': assert build_options.architectures == {Architecture.x86_64}
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch): monkeypatch.setenv("CIBW_ARCHS", "unused") monkeypatch.setenv("CIBW_ARCHS_LINUX", "ppc64le") monkeypatch.setenv("CIBW_ARCHS_WINDOWS", "x86") monkeypatch.setenv("CIBW_ARCHS_MACOS", "x86_64") main() options = intercepted_build_args.args[0] if platform == "linux": assert options.globals.architectures == {Architecture.ppc64le} elif platform == "windows": assert options.globals.architectures == {Architecture.x86} elif platform == "macos": assert options.globals.architectures == {Architecture.x86_64}