feat: allow-empty and simpler testing
This commit is contained in:
committed by
Henry Schreiner
parent
eb9850dbde
commit
5762aa5e3b
@@ -95,6 +95,9 @@ def main() -> None:
|
|||||||
parser.add_argument('--print-build-identifiers',
|
parser.add_argument('--print-build-identifiers',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Print the build identifiers matched by the current invocation and exit.')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -267,8 +270,9 @@ def main() -> None:
|
|||||||
assert_never(platform)
|
assert_never(platform)
|
||||||
|
|
||||||
if not identifiers:
|
if not identifiers:
|
||||||
print("ERROR: No build identifiers selected!")
|
print(f'cibuildwheel: No build identifiers selected: {build_selector}', file=sys.stderr)
|
||||||
sys.exit(3)
|
if not args.allow_empty:
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
|
||||||
def detect_obsolete_options() -> None:
|
def detect_obsolete_options() -> None:
|
||||||
|
|||||||
@@ -5,9 +5,3 @@ requires = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
build-backend = "setuptools.build_meta"
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
|
||||||
markers = [
|
|
||||||
"allow_empty(platform): Allow main tests on this platform(s) to be empty",
|
|
||||||
]
|
|
||||||
|
|||||||
@@ -52,8 +52,15 @@ def fake_package_dir(monkeypatch):
|
|||||||
else:
|
else:
|
||||||
return real_path_exists(path)
|
return real_path_exists(path)
|
||||||
|
|
||||||
|
args = ['cibuildwheel', str(MOCK_PACKAGE_DIR)]
|
||||||
monkeypatch.setattr(Path, 'exists', mock_path_exists)
|
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'])
|
@pytest.fixture(params=['linux', 'macos', 'windows'])
|
||||||
@@ -66,14 +73,6 @@ def platform(request, monkeypatch):
|
|||||||
else:
|
else:
|
||||||
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
|
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
|
return platform_value
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
assert intercepted_build_args.args[0].output_dir == OUTPUT_DIR
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.allow_empty
|
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty):
|
||||||
def test_build_selector(platform, intercepted_build_args, monkeypatch):
|
|
||||||
BUILD = 'some build* *-selector'
|
BUILD = 'some build* *-selector'
|
||||||
SKIP = 'some skip* *-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
|
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_name', ['CIBW_BUILD', 'CIBW_SKIP'])
|
||||||
@pytest.mark.parametrize('option_value, build_selector_patterns', [
|
@pytest.mark.parametrize('option_value, build_selector_patterns', [
|
||||||
('*-manylinux1_*', ['*-manylinux_*']),
|
('*-manylinux1_*', ['*-manylinux_*']),
|
||||||
@@ -231,7 +229,7 @@ def test_build_verbosity(build_verbosity, platform_specific, platform, intercept
|
|||||||
('*-macosx_10_9_x86_64', ['*-macosx_x86_64']),
|
('*-macosx_10_9_x86_64', ['*-macosx_x86_64']),
|
||||||
('cp37-macosx_10_9_x86_64', ['cp37-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)
|
monkeypatch.setenv(option_name, option_value)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -67,22 +67,25 @@ def test_platform_environment(platform, intercepted_build_args, monkeypatch):
|
|||||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
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):
|
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()
|
main()
|
||||||
build_options = intercepted_build_args.args[0]
|
build_options = intercepted_build_args.args[0]
|
||||||
|
|
||||||
if platform == 'linux':
|
if platform == 'linux':
|
||||||
assert build_options.architectures == {Architecture.x86_64, Architecture.i686}
|
assert build_options.architectures == {Architecture.x86_64, Architecture.i686}
|
||||||
|
elif platform == 'windows':
|
||||||
|
assert build_options.architectures == {Architecture.AMD64, Architecture.x86}
|
||||||
else:
|
else:
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.allow_empty('windows')
|
|
||||||
@pytest.mark.parametrize('use_env_var', [False, True])
|
@pytest.mark.parametrize('use_env_var', [False, True])
|
||||||
def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var):
|
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')
|
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
|
||||||
if use_env_var:
|
if use_env_var:
|
||||||
monkeypatch.setenv('CIBW_ARCHS', 'ppc64le')
|
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}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.allow_empty('windows')
|
|
||||||
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
|
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')
|
monkeypatch.setenv('CIBW_ARCHS', 'native')
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@@ -125,7 +127,7 @@ def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
|
|||||||
if platform == 'linux':
|
if platform == 'linux':
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
elif platform == 'windows':
|
elif platform == 'windows':
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.AMD64}
|
||||||
elif platform == 'macos':
|
elif platform == 'macos':
|
||||||
assert build_options.architectures == {Architecture.x86_64}
|
assert build_options.architectures == {Architecture.x86_64}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user