From 5762aa5e3bb77661c22817ab616e40d7de316441 Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Tue, 19 Jan 2021 20:52:06 -0500 Subject: [PATCH] feat: allow-empty and simpler testing --- cibuildwheel/__main__.py | 8 ++++++-- pyproject.toml | 6 ------ unit_test/main_tests/conftest.py | 17 ++++++++--------- unit_test/main_tests/main_options_test.py | 6 ++---- unit_test/main_tests/main_platform_test.py | 14 ++++++++------ 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 068897dc..bcdfef8c 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -95,6 +95,9 @@ def main() -> None: parser.add_argument('--print-build-identifiers', action='store_true', help='Print the build identifiers matched by the current invocation and exit.') + parser.add_argument('--allow-empty', + action='store_true', + help='Do not report an error code if the build does not match any wheels.') args = parser.parse_args() @@ -267,8 +270,9 @@ def main() -> None: assert_never(platform) if not identifiers: - print("ERROR: No build identifiers selected!") - sys.exit(3) + print(f'cibuildwheel: No build identifiers selected: {build_selector}', file=sys.stderr) + if not args.allow_empty: + sys.exit(3) def detect_obsolete_options() -> None: diff --git a/pyproject.toml b/pyproject.toml index c05fec7d..285367ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,9 +5,3 @@ requires = [ ] build-backend = "setuptools.build_meta" - - -[tool.pytest.ini_options] -markers = [ - "allow_empty(platform): Allow main tests on this platform(s) to be empty", -] diff --git a/unit_test/main_tests/conftest.py b/unit_test/main_tests/conftest.py index c70ff98e..3ce025a0 100644 --- a/unit_test/main_tests/conftest.py +++ b/unit_test/main_tests/conftest.py @@ -52,8 +52,15 @@ def fake_package_dir(monkeypatch): else: return real_path_exists(path) + args = ['cibuildwheel', str(MOCK_PACKAGE_DIR)] monkeypatch.setattr(Path, 'exists', mock_path_exists) - monkeypatch.setattr(sys, 'argv', ['cibuildwheel', str(MOCK_PACKAGE_DIR)]) + monkeypatch.setattr(sys, 'argv', args) + return args + + +@pytest.fixture +def allow_empty(request, monkeypatch, fake_package_dir): + monkeypatch.setattr(sys, 'argv', fake_package_dir + ['--allow-empty']) @pytest.fixture(params=['linux', 'macos', 'windows']) @@ -66,14 +73,6 @@ def platform(request, monkeypatch): else: monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') - marker = request.node.get_closest_marker('allow_empty') - if marker is not None and (len(marker.args) == 0 or platform_value in marker.args): - def pass_exit(val: int): - if val not in {3}: - sys.exit(val) - - monkeypatch.setattr(sys, 'exit', pass_exit) - return platform_value diff --git a/unit_test/main_tests/main_options_test.py b/unit_test/main_tests/main_options_test.py index 345cfe2a..f6c80ff7 100644 --- a/unit_test/main_tests/main_options_test.py +++ b/unit_test/main_tests/main_options_test.py @@ -40,8 +40,7 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR -@pytest.mark.allow_empty -def test_build_selector(platform, intercepted_build_args, monkeypatch): +def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty): BUILD = 'some build* *-selector' SKIP = 'some skip* *-selector' @@ -223,7 +222,6 @@ def test_build_verbosity(build_verbosity, platform_specific, platform, intercept assert intercepted_build_args.args[0].build_verbosity == expected_verbosity -@pytest.mark.allow_empty @pytest.mark.parametrize('option_name', ['CIBW_BUILD', 'CIBW_SKIP']) @pytest.mark.parametrize('option_value, build_selector_patterns', [ ('*-manylinux1_*', ['*-manylinux_*']), @@ -231,7 +229,7 @@ def test_build_verbosity(build_verbosity, platform_specific, platform, intercept ('*-macosx_10_9_x86_64', ['*-macosx_x86_64']), ('cp37-macosx_10_9_x86_64', ['cp37-macosx_x86_64']), ]) -def test_build_selector_migrations(intercepted_build_args, monkeypatch, option_name, option_value, build_selector_patterns): +def test_build_selector_migrations(intercepted_build_args, monkeypatch, option_name, option_value, build_selector_patterns, allow_empty): monkeypatch.setenv(option_name, option_value) main() diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index 0f277afe..844cf811 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -67,22 +67,25 @@ def test_platform_environment(platform, intercepted_build_args, monkeypatch): assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR -@pytest.mark.allow_empty('windows') def test_archs_default(platform, intercepted_build_args, monkeypatch): - monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') + monkeypatch.setattr(platform_module, 'machine', lambda: 'AMD64' if platform == 'windows' else 'x86_64') 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} -@pytest.mark.allow_empty('windows') @pytest.mark.parametrize('use_env_var', [False, True]) def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var): + if platform == 'windows': + pytest.skip('Will have empty build selectors on Windows') + monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') if use_env_var: monkeypatch.setenv('CIBW_ARCHS', 'ppc64le') @@ -114,9 +117,8 @@ def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch): assert build_options.architectures == {Architecture.x86_64} -@pytest.mark.allow_empty('windows') def test_archs_platform_native(platform, intercepted_build_args, monkeypatch): - monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64') + monkeypatch.setattr(platform_module, 'machine', lambda: 'AMD64' if platform == 'windows' else 'x86_64') monkeypatch.setenv('CIBW_ARCHS', 'native') main() @@ -125,7 +127,7 @@ def test_archs_platform_native(platform, intercepted_build_args, monkeypatch): if platform == 'linux': assert build_options.architectures == {Architecture.x86_64} elif platform == 'windows': - assert build_options.architectures == {Architecture.x86_64} + assert build_options.architectures == {Architecture.AMD64} elif platform == 'macos': assert build_options.architectures == {Architecture.x86_64}