Add unit test for the option parsing
This commit is contained in:
@@ -70,5 +70,14 @@ def platform(request, monkeypatch):
|
||||
@pytest.fixture
|
||||
def intercepted_build_args(platform, monkeypatch):
|
||||
intercepted = ArgsInterceptor()
|
||||
monkeypatch.setattr(globals()[platform], 'build', intercepted)
|
||||
|
||||
if platform == 'linux':
|
||||
monkeypatch.setattr(linux, 'build', intercepted)
|
||||
elif platform == 'macos':
|
||||
monkeypatch.setattr(macos, 'build', intercepted)
|
||||
elif platform == 'windows':
|
||||
monkeypatch.setattr(windows, 'build', intercepted)
|
||||
else:
|
||||
raise ValueError(f'unknown platform value: {platform}')
|
||||
|
||||
return intercepted
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import platform as platform_module
|
||||
from cibuildwheel.util import Architecture
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
@@ -64,3 +66,30 @@ def test_platform_environment(platform, intercepted_build_args, monkeypatch):
|
||||
main()
|
||||
|
||||
assert intercepted_build_args.args[0].package_dir == MOCK_PACKAGE_DIR
|
||||
|
||||
|
||||
def test_archs_default(platform, intercepted_build_args, monkeypatch):
|
||||
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
|
||||
if platform == 'linux':
|
||||
assert build_options.architectures == [Architecture.x86_64, Architecture.i686]
|
||||
else:
|
||||
assert build_options.architectures == [Architecture.x86_64]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_env_var', [False, True])
|
||||
def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var):
|
||||
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
|
||||
if use_env_var:
|
||||
monkeypatch.setenv('CIBW_ARCHS', 'ppc64le')
|
||||
else:
|
||||
monkeypatch.setenv('CIBW_ARCHS', 'unused')
|
||||
monkeypatch.setattr(sys, 'argv', sys.argv + ['--archs', 'ppc64le'])
|
||||
|
||||
main()
|
||||
build_options = intercepted_build_args.args[0]
|
||||
|
||||
assert build_options.architectures == [Architecture.ppc64le]
|
||||
|
||||
Reference in New Issue
Block a user