style: activate string normalization

This commit is contained in:
Henry Schreiner
2021-05-03 13:12:36 -04:00
committed by Henry Schreiner
parent d1900f6a05
commit bda76b21cb
54 changed files with 1598 additions and 1599 deletions
+68 -68
View File
@@ -6,21 +6,21 @@ from cibuildwheel.util import BuildSelector
def test_build():
build_selector = BuildSelector(build_config="cp3?-* *-manylinux1*", skip_config="")
assert build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert build_selector('cp27-manylinux1_i686')
assert build_selector('cp36-manylinux1_i686')
assert build_selector('cp37-manylinux1_i686')
assert not build_selector('cp27-macosx_10_6_intel')
assert build_selector('cp36-macosx_10_6_intel')
assert build_selector('cp37-macosx_10_6_intel')
assert not build_selector('cp27-win32')
assert build_selector('cp36-win32')
assert build_selector('cp37-win32')
assert not build_selector('cp27-win_amd64')
assert build_selector('cp36-win_amd64')
assert build_selector('cp37-win_amd64')
assert build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
assert build_selector("cp27-manylinux1_i686")
assert build_selector("cp36-manylinux1_i686")
assert build_selector("cp37-manylinux1_i686")
assert not build_selector("cp27-macosx_10_6_intel")
assert build_selector("cp36-macosx_10_6_intel")
assert build_selector("cp37-macosx_10_6_intel")
assert not build_selector("cp27-win32")
assert build_selector("cp36-win32")
assert build_selector("cp37-win32")
assert not build_selector("cp27-win_amd64")
assert build_selector("cp36-win_amd64")
assert build_selector("cp37-win_amd64")
def test_skip():
@@ -28,21 +28,21 @@ def test_skip():
build_config="*", skip_config="cp27-* cp3?-manylinux1_i686 cp36-win* *-win32"
)
assert not build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert not build_selector('cp27-manylinux1_i686')
assert not build_selector('cp36-manylinux1_i686')
assert not build_selector('cp37-manylinux1_i686')
assert not build_selector('cp27-macosx_10_6_intel')
assert build_selector('cp36-macosx_10_6_intel')
assert build_selector('cp37-macosx_10_6_intel')
assert not build_selector('cp27-win32')
assert not build_selector('cp36-win32')
assert not build_selector('cp37-win32')
assert not build_selector('cp27-win_amd64')
assert not build_selector('cp36-win_amd64')
assert build_selector('cp37-win_amd64')
assert not build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
assert not build_selector("cp27-manylinux1_i686")
assert not build_selector("cp36-manylinux1_i686")
assert not build_selector("cp37-manylinux1_i686")
assert not build_selector("cp27-macosx_10_6_intel")
assert build_selector("cp36-macosx_10_6_intel")
assert build_selector("cp37-macosx_10_6_intel")
assert not build_selector("cp27-win32")
assert not build_selector("cp36-win32")
assert not build_selector("cp37-win32")
assert not build_selector("cp27-win_amd64")
assert not build_selector("cp36-win_amd64")
assert build_selector("cp37-win_amd64")
def test_build_and_skip():
@@ -50,31 +50,31 @@ def test_build_and_skip():
build_config="cp36-* cp37-macosx* *-manylinux1*", skip_config="cp27-* cp37-manylinux1_i686"
)
assert not build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert not build_selector('cp27-manylinux1_i686')
assert build_selector('cp36-manylinux1_i686')
assert not build_selector('cp37-manylinux1_i686')
assert not build_selector('cp27-macosx_10_6_intel')
assert build_selector('cp36-macosx_10_6_intel')
assert build_selector('cp37-macosx_10_6_intel')
assert not build_selector('cp27-win32')
assert build_selector('cp36-win32')
assert not build_selector('cp37-win32')
assert not build_selector('cp27-win_amd64')
assert build_selector('cp36-win_amd64')
assert not build_selector('cp37-win_amd64')
assert not build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
assert not build_selector("cp27-manylinux1_i686")
assert build_selector("cp36-manylinux1_i686")
assert not build_selector("cp37-manylinux1_i686")
assert not build_selector("cp27-macosx_10_6_intel")
assert build_selector("cp36-macosx_10_6_intel")
assert build_selector("cp37-macosx_10_6_intel")
assert not build_selector("cp27-win32")
assert build_selector("cp36-win32")
assert not build_selector("cp37-win32")
assert not build_selector("cp27-win_amd64")
assert build_selector("cp36-win_amd64")
assert not build_selector("cp37-win_amd64")
def test_build_braces():
build_selector = BuildSelector(build_config="cp{36,37}*", skip_config="")
assert not build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert not build_selector('cp38-manylinux1_x86_64')
assert not build_selector('cp39-manylinux1_x86_64')
assert not build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
assert not build_selector("cp38-manylinux1_x86_64")
assert not build_selector("cp39-manylinux1_x86_64")
def test_build_limited_python():
@@ -82,18 +82,18 @@ def test_build_limited_python():
build_config="*", skip_config="", requires_python=SpecifierSet(">=3.6")
)
assert not build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert not build_selector('cp27-manylinux1_i686')
assert build_selector('cp36-manylinux1_i686')
assert build_selector('cp37-manylinux1_i686')
assert not build_selector('cp27-win32')
assert build_selector('cp36-win32')
assert build_selector('cp37-win32')
assert not build_selector('pp27-win32')
assert build_selector('pp36-win32')
assert build_selector('pp37-win32')
assert not build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
assert not build_selector("cp27-manylinux1_i686")
assert build_selector("cp36-manylinux1_i686")
assert build_selector("cp37-manylinux1_i686")
assert not build_selector("cp27-win32")
assert build_selector("cp36-win32")
assert build_selector("cp37-win32")
assert not build_selector("pp27-win32")
assert build_selector("pp36-win32")
assert build_selector("pp37-win32")
def test_build_limited_python_partial():
@@ -103,9 +103,9 @@ def test_build_limited_python_partial():
requires_python=SpecifierSet(">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*"),
)
assert build_selector('cp27-manylinux1_x86_64')
assert not build_selector('cp35-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector("cp27-manylinux1_x86_64")
assert not build_selector("cp35-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
def test_build_limited_python_patch():
@@ -113,6 +113,6 @@ def test_build_limited_python_patch():
build_config="*", skip_config="", requires_python=SpecifierSet(">=2.7.9")
)
assert build_selector('cp27-manylinux1_x86_64')
assert build_selector('cp36-manylinux1_x86_64')
assert build_selector('cp37-manylinux1_x86_64')
assert build_selector("cp27-manylinux1_x86_64")
assert build_selector("cp36-manylinux1_x86_64")
assert build_selector("cp37-manylinux1_x86_64")
+12 -12
View File
@@ -7,21 +7,21 @@ def test_defaults():
dependency_constraints = DependencyConstraints.with_defaults()
project_root = Path(__file__).parents[1]
resources_dir = project_root / 'cibuildwheel' / 'resources'
resources_dir = project_root / "cibuildwheel" / "resources"
assert dependency_constraints.base_file_path.samefile(resources_dir / 'constraints.txt')
assert dependency_constraints.get_for_python_version('3.99').samefile(
resources_dir / 'constraints.txt'
assert dependency_constraints.base_file_path.samefile(resources_dir / "constraints.txt")
assert dependency_constraints.get_for_python_version("3.99").samefile(
resources_dir / "constraints.txt"
)
assert dependency_constraints.get_for_python_version('3.9').samefile(
resources_dir / 'constraints-python39.txt'
assert dependency_constraints.get_for_python_version("3.9").samefile(
resources_dir / "constraints-python39.txt"
)
assert dependency_constraints.get_for_python_version('3.6').samefile(
resources_dir / 'constraints-python36.txt'
assert dependency_constraints.get_for_python_version("3.6").samefile(
resources_dir / "constraints-python36.txt"
)
assert dependency_constraints.get_for_python_version('3.5').samefile(
resources_dir / 'constraints-python35.txt'
assert dependency_constraints.get_for_python_version("3.5").samefile(
resources_dir / "constraints-python35.txt"
)
assert dependency_constraints.get_for_python_version('2.7').samefile(
resources_dir / 'constraints-python27.txt'
assert dependency_constraints.get_for_python_version("2.7").samefile(
resources_dir / "constraints-python27.txt"
)
+45 -45
View File
@@ -14,25 +14,25 @@ from cibuildwheel.environment import EnvironmentAssignment
# multi architectures and include python3.8
pm = platform.machine()
if pm == "x86_64":
DEFAULT_IMAGE = 'quay.io/pypa/manylinux2014_x86_64:2020-05-17-2f8ac3b'
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_x86_64:2020-05-17-2f8ac3b"
elif pm == "aarch64":
DEFAULT_IMAGE = 'quay.io/pypa/manylinux2014_aarch64:2020-05-17-2f8ac3b'
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_aarch64:2020-05-17-2f8ac3b"
elif pm == "ppc64le":
DEFAULT_IMAGE = 'quay.io/pypa/manylinux2014_ppc64le:2020-05-17-2f8ac3b'
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_ppc64le:2020-05-17-2f8ac3b"
elif pm == "s390x":
DEFAULT_IMAGE = 'quay.io/pypa/manylinux2014_s390x:2020-05-17-2f8ac3b'
DEFAULT_IMAGE = "quay.io/pypa/manylinux2014_s390x:2020-05-17-2f8ac3b"
@pytest.mark.docker
def test_simple():
with DockerContainer(DEFAULT_IMAGE) as container:
assert container.call(['echo', 'hello'], capture_output=True) == 'hello\n'
assert container.call(["echo", "hello"], capture_output=True) == "hello\n"
@pytest.mark.docker
def test_no_lf():
with DockerContainer(DEFAULT_IMAGE) as container:
assert container.call(['printf', 'hello'], capture_output=True) == 'hello'
assert container.call(["printf", "hello"], capture_output=True) == "hello"
@pytest.mark.docker
@@ -40,24 +40,24 @@ def test_environment():
with DockerContainer(DEFAULT_IMAGE) as container:
assert (
container.call(
['sh', '-c', 'echo $TEST_VAR'], env={'TEST_VAR': '1'}, capture_output=True
["sh", "-c", "echo $TEST_VAR"], env={"TEST_VAR": "1"}, capture_output=True
)
== '1\n'
== "1\n"
)
@pytest.mark.docker
def test_cwd():
with DockerContainer(DEFAULT_IMAGE, cwd='/cibuildwheel/working_directory') as container:
assert container.call(['pwd'], capture_output=True) == '/cibuildwheel/working_directory\n'
assert container.call(['pwd'], capture_output=True, cwd='/opt') == '/opt\n'
with DockerContainer(DEFAULT_IMAGE, cwd="/cibuildwheel/working_directory") as container:
assert container.call(["pwd"], capture_output=True) == "/cibuildwheel/working_directory\n"
assert container.call(["pwd"], capture_output=True, cwd="/opt") == "/opt\n"
@pytest.mark.docker
def test_container_removed():
with DockerContainer(DEFAULT_IMAGE) as container:
docker_containers_listing = subprocess.run(
'docker container ls',
"docker container ls",
shell=True,
check=True,
stdout=subprocess.PIPE,
@@ -67,7 +67,7 @@ def test_container_removed():
old_container_name = container.name
docker_containers_listing = subprocess.run(
'docker container ls',
"docker container ls",
shell=True,
check=True,
stdout=subprocess.PIPE,
@@ -81,17 +81,17 @@ def test_large_environment():
# max environment variable size is 128kB
long_env_var_length = 127 * 1024
large_environment = {
'a': '0' * long_env_var_length,
'b': '0' * long_env_var_length,
'c': '0' * long_env_var_length,
'd': '0' * long_env_var_length,
"a": "0" * long_env_var_length,
"b": "0" * long_env_var_length,
"c": "0" * long_env_var_length,
"d": "0" * long_env_var_length,
}
with DockerContainer(DEFAULT_IMAGE) as container:
# check the length of d
assert (
container.call(['sh', '-c', 'echo ${#d}'], env=large_environment, capture_output=True)
== f'{long_env_var_length}\n'
container.call(["sh", "-c", "echo ${#d}"], env=large_environment, capture_output=True)
== f"{long_env_var_length}\n"
)
@@ -103,13 +103,13 @@ def test_binary_output():
# check that we can pass though arbitrary binary data without erroring
container.call(
[
'/usr/bin/python2',
'-c',
"/usr/bin/python2",
"-c",
textwrap.dedent(
'''
"""
import sys
sys.stdout.write(''.join(chr(n) for n in range(0, 256)))
'''
"""
),
]
)
@@ -117,19 +117,19 @@ def test_binary_output():
# check that we can capture arbitrary binary data
output = container.call(
[
'/usr/bin/python2',
'-c',
"/usr/bin/python2",
"-c",
textwrap.dedent(
'''
"""
import sys
sys.stdout.write(''.join(chr(n % 256) for n in range(0, 512)))
'''
"""
),
],
capture_output=True,
)
data = bytes(output, encoding='utf8', errors='surrogateescape')
data = bytes(output, encoding="utf8", errors="surrogateescape")
for i in range(512):
assert data[i] == i % 256
@@ -137,10 +137,10 @@ def test_binary_output():
# check that environment variables can carry binary data, except null characters
# (https://www.gnu.org/software/libc/manual/html_node/Environment-Variables.html)
binary_data = bytes(n for n in range(1, 256))
binary_data_string = str(binary_data, encoding='utf8', errors='surrogateescape')
binary_data_string = str(binary_data, encoding="utf8", errors="surrogateescape")
output = container.call(
['python2', '-c', 'import os, sys; sys.stdout.write(os.environ["TEST_VAR"])'],
env={'TEST_VAR': binary_data_string},
["python2", "-c", 'import os, sys; sys.stdout.write(os.environ["TEST_VAR"])'],
env={"TEST_VAR": binary_data_string},
capture_output=True,
)
assert output == binary_data_string
@@ -151,45 +151,45 @@ def test_file_operations(tmp_path: Path):
with DockerContainer(DEFAULT_IMAGE) as container:
# test copying a file in
test_binary_data = bytes(random.randrange(256) for _ in range(1000))
original_test_file = tmp_path / 'test.dat'
original_test_file = tmp_path / "test.dat"
original_test_file.write_bytes(test_binary_data)
dst_file = PurePath('/tmp/test.dat')
dst_file = PurePath("/tmp/test.dat")
container.copy_into(original_test_file, dst_file)
output = container.call(['cat', dst_file], capture_output=True)
assert test_binary_data == bytes(output, encoding='utf8', errors='surrogateescape')
output = container.call(["cat", dst_file], capture_output=True)
assert test_binary_data == bytes(output, encoding="utf8", errors="surrogateescape")
@pytest.mark.docker
def test_dir_operations(tmp_path: Path):
with DockerContainer(DEFAULT_IMAGE) as container:
test_binary_data = bytes(random.randrange(256) for _ in range(1000))
original_test_file = tmp_path / 'test.dat'
original_test_file = tmp_path / "test.dat"
original_test_file.write_bytes(test_binary_data)
# test copying a dir in
test_dir = tmp_path / 'test_dir'
test_dir = tmp_path / "test_dir"
test_dir.mkdir()
test_file = test_dir / 'test.dat'
test_file = test_dir / "test.dat"
shutil.copyfile(original_test_file, test_file)
dst_dir = PurePath('/tmp/test_dir')
dst_file = dst_dir / 'test.dat'
dst_dir = PurePath("/tmp/test_dir")
dst_file = dst_dir / "test.dat"
container.copy_into(test_dir, dst_dir)
output = container.call(['cat', dst_file], capture_output=True)
assert test_binary_data == bytes(output, encoding='utf8', errors='surrogateescape')
output = container.call(["cat", dst_file], capture_output=True)
assert test_binary_data == bytes(output, encoding="utf8", errors="surrogateescape")
# test glob
assert container.glob(dst_dir, '*.dat') == [dst_file]
assert container.glob(dst_dir, "*.dat") == [dst_file]
# test copy dir out
new_test_dir = tmp_path / 'test_dir_new'
new_test_dir = tmp_path / "test_dir_new"
container.copy_out(dst_dir, new_test_dir)
assert test_binary_data == (new_test_dir / 'test.dat').read_bytes()
assert test_binary_data == (new_test_dir / "test.dat").read_bytes()
@pytest.mark.docker
+9 -9
View File
@@ -5,27 +5,27 @@ import pytest
from cibuildwheel.util import download
DOWNLOAD_URL = 'https://raw.githubusercontent.com/joerick/cibuildwheel/v1.6.3/requirements-dev.txt'
DOWNLOAD_URL = "https://raw.githubusercontent.com/joerick/cibuildwheel/v1.6.3/requirements-dev.txt"
def test_download(monkeypatch, tmp_path):
monkeypatch.delenv('SSL_CERT_FILE', raising=False)
dest = tmp_path / 'file.txt'
monkeypatch.delenv("SSL_CERT_FILE", raising=False)
dest = tmp_path / "file.txt"
download(DOWNLOAD_URL, dest)
assert len(dest.read_bytes()) == 134
def test_download_good_ssl_cert_file(monkeypatch, tmp_path):
monkeypatch.setenv('SSL_CERT_FILE', certifi.where())
dest = tmp_path / 'file.txt'
monkeypatch.setenv("SSL_CERT_FILE", certifi.where())
dest = tmp_path / "file.txt"
download(DOWNLOAD_URL, dest)
assert len(dest.read_bytes()) == 134
def test_download_bad_ssl_cert_file(monkeypatch, tmp_path):
bad_cafile = tmp_path / 'ca.pem'
bad_cafile.write_text('bad certificates')
monkeypatch.setenv('SSL_CERT_FILE', str(bad_cafile))
dest = tmp_path / 'file.txt'
bad_cafile = tmp_path / "ca.pem"
bad_cafile.write_text("bad certificates")
monkeypatch.setenv("SSL_CERT_FILE", str(bad_cafile))
dest = tmp_path / "file.txt"
with pytest.raises(ssl.SSLError):
download(DOWNLOAD_URL, dest)
+27 -27
View File
@@ -4,70 +4,70 @@ from cibuildwheel.environment import parse_environment
def test_basic_parsing():
environment_recipe = parse_environment('VAR=1 VBR=2')
environment_recipe = parse_environment("VAR=1 VBR=2")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict == {'VAR': '1', 'VBR': '2'}
assert environment_cmds == ['export VAR=1', 'export VBR=2']
assert environment_dict == {"VAR": "1", "VBR": "2"}
assert environment_cmds == ["export VAR=1", "export VBR=2"]
def test_quotes():
environment_recipe = parse_environment('A=1 VAR="1 NOT_A_VAR=2" VBR=\'vbr\'')
environment_recipe = parse_environment("A=1 VAR=\"1 NOT_A_VAR=2\" VBR='vbr'")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict == {'A': '1', 'VAR': '1 NOT_A_VAR=2', 'VBR': 'vbr'}
assert environment_cmds == ['export A=1', 'export VAR="1 NOT_A_VAR=2"', 'export VBR=\'vbr\'']
assert environment_dict == {"A": "1", "VAR": "1 NOT_A_VAR=2", "VBR": "vbr"}
assert environment_cmds == ["export A=1", 'export VAR="1 NOT_A_VAR=2"', "export VBR='vbr'"]
def test_inheritance():
environment_recipe = parse_environment('PATH=$PATH:/usr/local/bin')
environment_recipe = parse_environment("PATH=$PATH:/usr/local/bin")
environment_dict = environment_recipe.as_dictionary(prev_environment={'PATH': '/usr/bin'})
environment_dict = environment_recipe.as_dictionary(prev_environment={"PATH": "/usr/bin"})
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict == {'PATH': '/usr/bin:/usr/local/bin'}
assert environment_cmds == ['export PATH=$PATH:/usr/local/bin']
assert environment_dict == {"PATH": "/usr/bin:/usr/local/bin"}
assert environment_cmds == ["export PATH=$PATH:/usr/local/bin"]
def test_shell_eval():
environment_recipe = parse_environment('VAR="$(echo "a test" string)"')
env_copy = os.environ.copy()
env_copy.pop('VAR', None)
env_copy.pop("VAR", None)
environment_dict = environment_recipe.as_dictionary(prev_environment=env_copy)
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict['VAR'] == 'a test string'
assert environment_dict["VAR"] == "a test string"
assert environment_cmds == ['export VAR="$(echo "a test" string)"']
def test_shell_eval_and_env():
environment_recipe = parse_environment('VAR="$(echo "$PREV_VAR" string)"')
environment_dict = environment_recipe.as_dictionary(prev_environment={'PREV_VAR': '1 2 3'})
environment_dict = environment_recipe.as_dictionary(prev_environment={"PREV_VAR": "1 2 3"})
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict == {'PREV_VAR': '1 2 3', 'VAR': '1 2 3 string'}
assert environment_dict == {"PREV_VAR": "1 2 3", "VAR": "1 2 3 string"}
assert environment_cmds == ['export VAR="$(echo "$PREV_VAR" string)"']
def test_empty_var():
environment_recipe = parse_environment('CFLAGS=')
environment_recipe = parse_environment("CFLAGS=")
environment_dict = environment_recipe.as_dictionary(prev_environment={'CFLAGS': '-Wall'})
environment_dict = environment_recipe.as_dictionary(prev_environment={"CFLAGS": "-Wall"})
environment_cmds = environment_recipe.as_shell_commands()
assert environment_dict == {'CFLAGS': ''}
assert environment_cmds == ['export CFLAGS=']
assert environment_dict == {"CFLAGS": ""}
assert environment_cmds == ["export CFLAGS="]
def test_no_vars():
environment_recipe = parse_environment('')
environment_recipe = parse_environment("")
environment_dict = environment_recipe.as_dictionary(prev_environment={})
environment_cmds = environment_recipe.as_shell_commands()
@@ -77,13 +77,13 @@ def test_no_vars():
def test_no_vars_pass_through():
environment_recipe = parse_environment('')
environment_recipe = parse_environment("")
environment_dict = environment_recipe.as_dictionary(
prev_environment={'CIBUILDWHEEL': 'awesome'}
prev_environment={"CIBUILDWHEEL": "awesome"}
)
assert environment_dict == {'CIBUILDWHEEL': 'awesome'}
assert environment_dict == {"CIBUILDWHEEL": "awesome"}
def test_operators_inside_eval():
@@ -92,16 +92,16 @@ def test_operators_inside_eval():
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary(os.environ.copy())
assert environment_dict.get('SOMETHING') == 'a\nb\nc'
assert environment_dict.get("SOMETHING") == "a\nb\nc"
def test_substitution_with_backslash():
environment_recipe = parse_environment('PATH2="somewhere_else;$PATH1"')
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary(prev_environment={'PATH1': 'c:\\folder\\'})
environment_dict = environment_recipe.as_dictionary(prev_environment={"PATH1": "c:\\folder\\"})
assert environment_dict.get('PATH2') == 'somewhere_else;c:\\folder\\'
assert environment_dict.get("PATH2") == "somewhere_else;c:\\folder\\"
def test_awkwardly_quoted_variable():
@@ -110,6 +110,6 @@ def test_awkwardly_quoted_variable():
)
# pass the existing process env so PATH is available
environment_dict = environment_recipe.as_dictionary({'VAR1': 'but wait'})
environment_dict = environment_recipe.as_dictionary({"VAR1": "but wait"})
assert environment_dict.get('VAR2') == 'somethinglike thisbut waitbut waittheres moreand more!'
assert environment_dict.get("VAR2") == "somethinglike thisbut waitbut waittheres moreand more!"
+31 -31
View File
@@ -15,15 +15,15 @@ class ArgsInterceptor:
self.kwargs = kwargs
MOCK_PACKAGE_DIR = Path('some_package_dir')
MOCK_PACKAGE_DIR = Path("some_package_dir")
@pytest.fixture(autouse=True)
def mock_protection(monkeypatch):
'''
"""
Ensure that a unit test will never actually run a cibuildwheel 'build'
function, which shouldn't be run on a developer's machine
'''
"""
def fail_on_call(*args, **kwargs):
raise RuntimeError("This should never be called")
@@ -31,31 +31,31 @@ def mock_protection(monkeypatch):
def ignore_call(*args, **kwargs):
pass
monkeypatch.setattr(subprocess, 'Popen', fail_on_call)
monkeypatch.setattr(util, 'download', fail_on_call)
monkeypatch.setattr(windows, 'build', fail_on_call)
monkeypatch.setattr(linux, 'build', fail_on_call)
monkeypatch.setattr(macos, 'build', fail_on_call)
monkeypatch.setattr(subprocess, "Popen", fail_on_call)
monkeypatch.setattr(util, "download", fail_on_call)
monkeypatch.setattr(windows, "build", fail_on_call)
monkeypatch.setattr(linux, "build", fail_on_call)
monkeypatch.setattr(macos, "build", fail_on_call)
monkeypatch.setattr(Path, 'mkdir', ignore_call)
monkeypatch.setattr(Path, "mkdir", ignore_call)
@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':
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)
args = ["cibuildwheel", str(MOCK_PACKAGE_DIR)]
monkeypatch.setattr(Path, "exists", mock_path_exists)
monkeypatch.setattr(sys, "argv", args)
return args
@@ -65,26 +65,26 @@ def disable_print_wheels(monkeypatch):
def empty_cm(*args, **kwargs):
yield
monkeypatch.setattr(util, 'print_new_wheels', empty_cm)
monkeypatch.setattr(util, "print_new_wheels", empty_cm)
@pytest.fixture
def allow_empty(request, monkeypatch, fake_package_dir):
monkeypatch.setattr(sys, 'argv', fake_package_dir + ['--allow-empty'])
monkeypatch.setattr(sys, "argv", fake_package_dir + ["--allow-empty"])
@pytest.fixture(params=['linux', 'macos', 'windows'])
@pytest.fixture(params=["linux", "macos", "windows"])
def platform(request, monkeypatch):
platform_value = request.param
monkeypatch.setenv('CIBW_PLATFORM', platform_value)
monkeypatch.setenv("CIBW_PLATFORM", platform_value)
if platform_value == 'windows':
monkeypatch.setattr(platform_module, 'machine', lambda: 'AMD64')
if platform_value == "windows":
monkeypatch.setattr(platform_module, "machine", lambda: "AMD64")
else:
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
monkeypatch.setattr(platform_module, "machine", lambda: "x86_64")
if platform_value == 'macos':
monkeypatch.setattr(macos, 'get_macos_version', lambda: (11, 1))
if platform_value == "macos":
monkeypatch.setattr(macos, "get_macos_version", lambda: (11, 1))
return platform_value
@@ -93,13 +93,13 @@ def platform(request, monkeypatch):
def intercepted_build_args(platform, monkeypatch):
intercepted = ArgsInterceptor()
if platform == 'linux':
monkeypatch.setattr(linux, 'build', intercepted)
elif platform == 'macos':
monkeypatch.setattr(macos, 'build', intercepted)
elif platform == 'windows':
monkeypatch.setattr(windows, '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}')
raise ValueError(f"unknown platform value: {platform}")
return intercepted
+92 -92
View File
@@ -12,9 +12,9 @@ from cibuildwheel.util import BuildSelector
def test_output_dir(platform, intercepted_build_args, monkeypatch):
OUTPUT_DIR = Path('some_output_dir')
OUTPUT_DIR = Path("some_output_dir")
monkeypatch.setenv('CIBW_OUTPUT_DIR', str(OUTPUT_DIR))
monkeypatch.setenv("CIBW_OUTPUT_DIR", str(OUTPUT_DIR))
main()
@@ -24,16 +24,16 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch):
def test_output_dir_default(platform, intercepted_build_args, monkeypatch):
main()
assert intercepted_build_args.args[0].output_dir == Path('wheelhouse')
assert intercepted_build_args.args[0].output_dir == Path("wheelhouse")
@pytest.mark.parametrize('also_set_environment', [False, True])
@pytest.mark.parametrize("also_set_environment", [False, True])
def test_output_dir_argument(also_set_environment, platform, intercepted_build_args, monkeypatch):
OUTPUT_DIR = Path('some_output_dir')
OUTPUT_DIR = Path("some_output_dir")
monkeypatch.setattr(sys, 'argv', sys.argv + ['--output-dir', str(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')
monkeypatch.setenv("CIBW_OUTPUT_DIR", "not_this_output_dir")
main()
@@ -41,24 +41,24 @@ def test_output_dir_argument(also_set_environment, platform, intercepted_build_a
def test_build_selector(platform, intercepted_build_args, monkeypatch, allow_empty):
BUILD = 'some build* *-selector'
SKIP = 'some skip* *-selector'
BUILD = "some build* *-selector"
SKIP = "some skip* *-selector"
monkeypatch.setenv('CIBW_BUILD', BUILD)
monkeypatch.setenv('CIBW_SKIP', SKIP)
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('build24-this')
assert not intercepted_build_selector('skip65-that')
assert intercepted_build_selector("build24-this")
assert not intercepted_build_selector("skip65-that")
# This unit test is just testing the options of 'main'
# Unit tests for BuildSelector are in build_selector_test.py
def test_empty_selector(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_SKIP', '*')
monkeypatch.setenv("CIBW_SKIP", "*")
with pytest.raises(SystemExit) as e:
main()
@@ -67,63 +67,63 @@ def test_empty_selector(platform, intercepted_build_args, monkeypatch):
@pytest.mark.parametrize(
'architecture, image, full_image',
"architecture, image, full_image",
[
('x86_64', None, 'quay.io/pypa/manylinux2010_x86_64:*'),
('x86_64', 'manylinux1', 'quay.io/pypa/manylinux1_x86_64:*'),
('x86_64', 'manylinux2010', 'quay.io/pypa/manylinux2010_x86_64:*'),
('x86_64', 'manylinux2014', 'quay.io/pypa/manylinux2014_x86_64:*'),
('x86_64', 'manylinux_2_24', 'quay.io/pypa/manylinux_2_24_x86_64:*'),
('x86_64', 'custom_image', 'custom_image'),
('i686', None, 'quay.io/pypa/manylinux2010_i686:*'),
('i686', 'manylinux1', 'quay.io/pypa/manylinux1_i686:*'),
('i686', 'manylinux2010', 'quay.io/pypa/manylinux2010_i686:*'),
('i686', 'manylinux2014', 'quay.io/pypa/manylinux2014_i686:*'),
('i686', 'manylinux_2_24', 'quay.io/pypa/manylinux_2_24_i686:*'),
('i686', 'custom_image', 'custom_image'),
('pypy_x86_64', None, 'pypywheels/manylinux2010-pypy_x86_64:*'),
('pypy_x86_64', 'manylinux1', 'manylinux1'), # Does not exist
('pypy_x86_64', 'manylinux2010', 'pypywheels/manylinux2010-pypy_x86_64:*'),
('pypy_x86_64', 'manylinux2014', 'manylinux2014'), # Does not exist (yet)
('pypy_x86_64', 'custom_image', 'custom_image'),
("x86_64", None, "quay.io/pypa/manylinux2010_x86_64:*"),
("x86_64", "manylinux1", "quay.io/pypa/manylinux1_x86_64:*"),
("x86_64", "manylinux2010", "quay.io/pypa/manylinux2010_x86_64:*"),
("x86_64", "manylinux2014", "quay.io/pypa/manylinux2014_x86_64:*"),
("x86_64", "manylinux_2_24", "quay.io/pypa/manylinux_2_24_x86_64:*"),
("x86_64", "custom_image", "custom_image"),
("i686", None, "quay.io/pypa/manylinux2010_i686:*"),
("i686", "manylinux1", "quay.io/pypa/manylinux1_i686:*"),
("i686", "manylinux2010", "quay.io/pypa/manylinux2010_i686:*"),
("i686", "manylinux2014", "quay.io/pypa/manylinux2014_i686:*"),
("i686", "manylinux_2_24", "quay.io/pypa/manylinux_2_24_i686:*"),
("i686", "custom_image", "custom_image"),
("pypy_x86_64", None, "pypywheels/manylinux2010-pypy_x86_64:*"),
("pypy_x86_64", "manylinux1", "manylinux1"), # Does not exist
("pypy_x86_64", "manylinux2010", "pypywheels/manylinux2010-pypy_x86_64:*"),
("pypy_x86_64", "manylinux2014", "manylinux2014"), # Does not exist (yet)
("pypy_x86_64", "custom_image", "custom_image"),
],
)
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)
monkeypatch.setenv("CIBW_MANYLINUX_" + architecture.upper() + "_IMAGE", image)
main()
if platform == 'linux':
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 get_default_repair_command(platform):
if platform == 'linux':
return 'auditwheel repair -w {dest_dir} {wheel}'
elif platform == 'macos':
return 'delocate-listdeps {wheel} && delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}'
elif platform == 'windows':
return ''
if platform == "linux":
return "auditwheel repair -w {dest_dir} {wheel}"
elif platform == "macos":
return "delocate-listdeps {wheel} && delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}"
elif platform == "windows":
return ""
else:
raise ValueError('Unknown platform', platform)
raise ValueError("Unknown platform", platform)
@pytest.mark.parametrize('repair_command', [None, 'repair', 'repair -w {dest_dir} {wheel}'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("repair_command", [None, "repair", "repair -w {dest_dir} {wheel}"])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
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)
monkeypatch.setenv("CIBW_REPAIR_WHEEL_COMMAND", repair_command)
main()
@@ -132,17 +132,17 @@ def test_repair_command(
@pytest.mark.parametrize(
'environment',
[{}, {'something': 'value'}, {'something': 'value', 'something_else': 'other_value'}],
"environment",
[{}, {"something": "value"}, {"something": "value", "something_else": "other_value"}],
)
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("platform_specific", [False, True])
def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch):
env_string = ' '.join(f'{k}={v}' for k, v in environment.items())
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')
monkeypatch.setenv("CIBW_ENVIRONMENT_" + platform.upper(), env_string)
monkeypatch.setenv("CIBW_ENVIRONMENT", "overwritten")
else:
monkeypatch.setenv('CIBW_ENVIRONMENT', env_string)
monkeypatch.setenv("CIBW_ENVIRONMENT", env_string)
main()
@@ -151,85 +151,85 @@ def test_environment(environment, platform_specific, platform, intercepted_build
assert intercepted_environment.as_dictionary(prev_environment={}) == environment
@pytest.mark.parametrize('test_requires', [None, 'requirement other_requirement'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("test_requires", [None, "requirement other_requirement"])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
monkeypatch.setenv("CIBW_TEST_REQUIRES_" + platform.upper(), test_requires)
monkeypatch.setenv("CIBW_TEST_REQUIRES", "overwritten")
else:
monkeypatch.setenv('CIBW_TEST_REQUIRES', test_requires)
monkeypatch.setenv("CIBW_TEST_REQUIRES", test_requires)
main()
assert intercepted_build_args.args[0].test_requires == (test_requires or '').split()
assert intercepted_build_args.args[0].test_requires == (test_requires or "").split()
@pytest.mark.parametrize('test_extras', [None, 'extras'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("test_extras", [None, "extras"])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
monkeypatch.setenv("CIBW_TEST_EXTRAS_" + platform.upper(), test_extras)
monkeypatch.setenv("CIBW_TEST_EXTRAS", "overwritten")
else:
monkeypatch.setenv('CIBW_TEST_EXTRAS', test_extras)
monkeypatch.setenv("CIBW_TEST_EXTRAS", test_extras)
main()
assert intercepted_build_args.args[0].test_extras == (
'[' + test_extras + ']' if test_extras else ''
"[" + test_extras + "]" if test_extras else ""
)
@pytest.mark.parametrize('test_command', [None, 'test --command'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("test_command", [None, "test --command"])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
monkeypatch.setenv("CIBW_TEST_COMMAND_" + platform.upper(), test_command)
monkeypatch.setenv("CIBW_TEST_COMMAND", "overwritten")
else:
monkeypatch.setenv('CIBW_TEST_COMMAND', test_command)
monkeypatch.setenv("CIBW_TEST_COMMAND", test_command)
main()
assert intercepted_build_args.args[0].test_command == test_command
@pytest.mark.parametrize('before_build', [None, 'before --build'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("before_build", [None, "before --build"])
@pytest.mark.parametrize("platform_specific", [False, True])
def test_before_build(
before_build, platform_specific, platform, intercepted_build_args, monkeypatch
):
if before_build is not None:
if platform_specific:
monkeypatch.setenv('CIBW_BEFORE_BUILD_' + platform.upper(), before_build)
monkeypatch.setenv('CIBW_BEFORE_BUILD', 'overwritten')
monkeypatch.setenv("CIBW_BEFORE_BUILD_" + platform.upper(), before_build)
monkeypatch.setenv("CIBW_BEFORE_BUILD", "overwritten")
else:
monkeypatch.setenv('CIBW_BEFORE_BUILD', before_build)
monkeypatch.setenv("CIBW_BEFORE_BUILD", before_build)
main()
assert intercepted_build_args.args[0].before_build == before_build
@pytest.mark.parametrize('build_verbosity', [None, 0, 2, -2, 4, -4])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("build_verbosity", [None, 0, 2, -2, 4, -4])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
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))
monkeypatch.setenv("CIBW_BUILD_VERBOSITY", str(build_verbosity))
main()
@@ -237,14 +237,14 @@ def test_build_verbosity(
assert intercepted_build_args.args[0].build_verbosity == expected_verbosity
@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',
"option_value, build_selector_patterns",
[
('*-manylinux1_*', ['*-manylinux_*']),
('*-macosx_10_6_intel', ['*-macosx_x86_64']),
('*-macosx_10_9_x86_64', ['*-macosx_x86_64']),
('cp37-macosx_10_9_x86_64', ['cp37-macosx_x86_64']),
("*-manylinux1_*", ["*-manylinux_*"]),
("*-macosx_10_6_intel", ["*-macosx_x86_64"]),
("*-macosx_10_9_x86_64", ["*-macosx_x86_64"]),
("cp37-macosx_10_9_x86_64", ["cp37-macosx_x86_64"]),
],
)
def test_build_selector_migrations(
@@ -262,21 +262,21 @@ def test_build_selector_migrations(
intercepted_build_selector = intercepted_build_args.args[0].build_selector
assert isinstance(intercepted_build_selector, BuildSelector)
if option_name == 'CIBW_BUILD':
if option_name == "CIBW_BUILD":
assert intercepted_build_selector.build_patterns == build_selector_patterns
else:
assert intercepted_build_selector.skip_patterns == build_selector_patterns
@pytest.mark.parametrize('before_all', ["", None, 'test text'])
@pytest.mark.parametrize('platform_specific', [False, True])
@pytest.mark.parametrize("before_all", ["", None, "test text"])
@pytest.mark.parametrize("platform_specific", [False, True])
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')
monkeypatch.setenv("CIBW_BEFORE_ALL_" + platform.upper(), before_all)
monkeypatch.setenv("CIBW_BEFORE_ALL", "overwritten")
else:
monkeypatch.setenv('CIBW_BEFORE_ALL', before_all)
monkeypatch.setenv("CIBW_BEFORE_ALL", before_all)
main()
+46 -46
View File
@@ -9,29 +9,29 @@ from .conftest import MOCK_PACKAGE_DIR
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('TRAVIS', raising=False)
monkeypatch.delenv('APPVEYOR', raising=False)
monkeypatch.delenv('GITHUB_ACTIONS', raising=False)
monkeypatch.delenv('GITLAB_CI', raising=False)
monkeypatch.delenv('CIRCLECI', raising=False)
monkeypatch.delenv('CIBW_PLATFORM', raising=False)
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("BITRISE_BUILD_NUMBER", raising=False)
monkeypatch.delenv("AZURE_HTTP_USER_AGENT", raising=False)
monkeypatch.delenv("TRAVIS", raising=False)
monkeypatch.delenv("APPVEYOR", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("GITLAB_CI", raising=False)
monkeypatch.delenv("CIRCLECI", raising=False)
monkeypatch.delenv("CIBW_PLATFORM", 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
assert "cibuildwheel: Unable to detect platform." in err
assert "cibuildwheel should run on your CI server" in err
def test_unknown_platform_on_ci(monkeypatch, capsys):
monkeypatch.setenv('CI', 'true')
monkeypatch.setattr(sys, 'platform', 'nonexistent')
monkeypatch.delenv('CIBW_PLATFORM', raising=False)
monkeypatch.setenv("CI", "true")
monkeypatch.setattr(sys, "platform", "nonexistent")
monkeypatch.delenv("CIBW_PLATFORM", raising=False)
with pytest.raises(SystemExit) as exit:
main()
@@ -42,19 +42,19 @@ def test_unknown_platform_on_ci(monkeypatch, capsys):
def test_unknown_platform(monkeypatch, capsys):
monkeypatch.setenv('CIBW_PLATFORM', 'nonexistent')
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
with pytest.raises(SystemExit) as exit:
main()
_, err = capsys.readouterr()
assert exit.value.code == 2
assert 'cibuildwheel: Unsupported platform: nonexistent' in err
assert "cibuildwheel: Unsupported platform: nonexistent" in err
def test_platform_argument(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_PLATFORM', 'nonexistent')
monkeypatch.setattr(sys, 'argv', sys.argv + ['--platform', platform])
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
monkeypatch.setattr(sys, "argv", sys.argv + ["--platform", platform])
main()
@@ -72,24 +72,24 @@ def test_archs_default(platform, intercepted_build_args, monkeypatch):
main()
build_options = intercepted_build_args.args[0]
if platform == 'linux':
if platform == "linux":
assert build_options.architectures == {Architecture.x86_64, Architecture.i686}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.AMD64, Architecture.x86}
else:
assert build_options.architectures == {Architecture.x86_64}
@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):
if use_env_var:
monkeypatch.setenv('CIBW_ARCHS', 'ppc64le')
monkeypatch.setenv("CIBW_ARCHS", "ppc64le")
else:
monkeypatch.setenv('CIBW_ARCHS', 'unused')
monkeypatch.setattr(sys, 'argv', sys.argv + ['--archs', 'ppc64le'])
monkeypatch.setenv("CIBW_ARCHS", "unused")
monkeypatch.setattr(sys, "argv", sys.argv + ["--archs", "ppc64le"])
if platform in {'macos', 'windows'}:
if platform in {"macos", "windows"}:
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.args == (4,)
@@ -101,50 +101,50 @@ def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_v
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')
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':
if platform == "linux":
assert build_options.architectures == {Architecture.ppc64le}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.x86}
elif platform == 'macos':
elif platform == "macos":
assert build_options.architectures == {Architecture.x86_64}
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_ARCHS', 'native')
monkeypatch.setenv("CIBW_ARCHS", "native")
main()
build_options = intercepted_build_args.args[0]
if platform in {'linux', 'macos'}:
if platform in {"linux", "macos"}:
assert build_options.architectures == {Architecture.x86_64}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.AMD64}
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_ARCHS', 'auto64')
monkeypatch.setenv("CIBW_ARCHS", "auto64")
main()
build_options = intercepted_build_args.args[0]
if platform in {'linux', 'macos'}:
if platform in {"linux", "macos"}:
assert build_options.architectures == {Architecture.x86_64}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.AMD64}
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_ARCHS', 'auto32')
monkeypatch.setenv("CIBW_ARCHS", "auto32")
if platform == 'macos':
if platform == "macos":
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.args == (4,)
@@ -154,19 +154,19 @@ def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
build_options = intercepted_build_args.args[0]
if platform == 'linux':
if platform == "linux":
assert build_options.architectures == {Architecture.i686}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.x86}
def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv('CIBW_ARCHS', 'all')
monkeypatch.setenv("CIBW_ARCHS", "all")
main()
build_options = intercepted_build_args.args[0]
if platform == 'linux':
if platform == "linux":
assert build_options.architectures == {
Architecture.x86_64,
Architecture.i686,
@@ -174,9 +174,9 @@ def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
Architecture.ppc64le,
Architecture.s390x,
}
elif platform == 'windows':
elif platform == "windows":
assert build_options.architectures == {Architecture.x86, Architecture.AMD64}
elif platform == 'macos':
elif platform == "macos":
assert build_options.architectures == {
Architecture.x86_64,
Architecture.arm64,
@@ -9,16 +9,16 @@ from cibuildwheel.__main__ import main
@pytest.fixture(autouse=True, scope="function")
def fake_package_dir(monkeypatch, tmp_path):
'''
"""
Set up a fake project
'''
"""
local_path = tmp_path / "tmp_project"
local_path.mkdir()
local_path.joinpath("setup.py").touch()
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', str(local_path)])
monkeypatch.setattr(sys, "argv", ["cibuildwheel", str(local_path)])
return local_path
@@ -29,14 +29,14 @@ def test_no_override(platform, monkeypatch, intercepted_build_args):
intercepted_build_selector = intercepted_build_args.args[0].build_selector
assert intercepted_build_selector('cp39-win32')
assert intercepted_build_selector('cp36-win32')
assert intercepted_build_selector("cp39-win32")
assert intercepted_build_selector("cp36-win32")
assert intercepted_build_selector.requires_python is None
def test_override_env(platform, monkeypatch, intercepted_build_args):
monkeypatch.setenv('CIBW_PROJECT_REQUIRES_PYTHON', '>=3.8')
monkeypatch.setenv("CIBW_PROJECT_REQUIRES_PYTHON", ">=3.8")
main()
@@ -44,8 +44,8 @@ def test_override_env(platform, monkeypatch, intercepted_build_args):
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
assert intercepted_build_selector('cp39-win32')
assert not intercepted_build_selector('cp36-win32')
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):
@@ -65,8 +65,8 @@ def test_override_setup_cfg(platform, monkeypatch, intercepted_build_args, fake_
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
assert intercepted_build_selector('cp39-win32')
assert not intercepted_build_selector('cp36-win32')
assert intercepted_build_selector("cp39-win32")
assert not intercepted_build_selector("cp36-win32")
def test_override_pyproject_toml(platform, monkeypatch, intercepted_build_args, fake_package_dir):
@@ -86,8 +86,8 @@ def test_override_pyproject_toml(platform, monkeypatch, intercepted_build_args,
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.8")
assert intercepted_build_selector('cp39-win32')
assert not intercepted_build_selector('cp36-win32')
assert intercepted_build_selector("cp39-win32")
assert not intercepted_build_selector("cp36-win32")
def test_override_setup_py_simple(platform, monkeypatch, intercepted_build_args, fake_package_dir):
@@ -111,5 +111,5 @@ def test_override_setup_py_simple(platform, monkeypatch, intercepted_build_args,
assert intercepted_build_selector.requires_python == SpecifierSet(">=3.7")
assert intercepted_build_selector('cp39-win32')
assert not intercepted_build_selector('cp36-win32')
assert intercepted_build_selector("cp39-win32")
assert not intercepted_build_selector("cp36-win32")