Skip to content

Commit 97da904

Browse files
authored
chore: rework single python tests (#1835)
* chore: rework single python tests * chore(tests): limit number of builds in test_abi3 * chore(tests): limit number of builds in test_before_all * apply review suggestion use `os.path.samefile` rather than comparing `os.stat` directly.
1 parent 67ee9dd commit 97da904

16 files changed

+143
-136
lines changed

test/test_abi_variants.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
CAN_USE_ABI3 = IS_CPYTHON and not Py_GIL_DISABLED
2121
cmdclass = {}
2222
extension_kwargs = {}
23-
if CAN_USE_ABI3 and sys.version_info[:2] >= (3, 8):
23+
if CAN_USE_ABI3 and sys.version_info[:2] >= (3, 10):
2424
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
2525
2626
class bdist_wheel_abi3(_bdist_wheel):
@@ -33,7 +33,7 @@ def get_tag(self):
3333
return python, "abi3", plat
3434
3535
cmdclass["bdist_wheel"] = bdist_wheel_abi3
36-
extension_kwargs["define_macros"] = [("Py_LIMITED_API", "0x03080000")]
36+
extension_kwargs["define_macros"] = [("Py_LIMITED_API", "0x030A0000")]
3737
extension_kwargs["py_limited_api"] = True
3838
"""
3939
),
@@ -53,17 +53,16 @@ def test_abi3(tmp_path):
5353
project_dir,
5454
add_env={
5555
# free_threaded and PyPy do not have a Py_LIMITED_API equivalent, just build one of those
56-
"CIBW_BUILD": "cp3?-* cp31?-* cp313t-* pp310-*"
56+
# also limit the number of builds for test performance reasons
57+
"CIBW_BUILD": "cp39-* cp310-* pp310-* cp311-* cp313t-*"
5758
},
5859
)
5960

6061
# check that the expected wheels are produced
6162
expected_wheels = [
62-
w.replace("cp38-cp38", "cp38-abi3")
63+
w.replace("cp310-cp310", "cp310-abi3")
6364
for w in utils.expected_wheels("spam", "0.1.0")
64-
if ("-pp310" in w or "-pp" not in w)
65-
and "-cp39" not in w
66-
and ("-cp313t" in w or "-cp31" not in w)
65+
if "-cp39" in w or "-cp310" in w or "-pp310" in w or "-cp313t" in w
6766
]
6867
assert set(actual_wheels) == set(expected_wheels)
6968

test/test_before_all.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@
1010
project_with_before_build_asserts = test_projects.new_c_project(
1111
setup_py_add=textwrap.dedent(
1212
r"""
13-
# assert that the Python version as written to text_info.txt in the CIBW_BEFORE_ALL step
14-
# is the same one as is currently running.
13+
import os
14+
1515
with open("text_info.txt") as f:
1616
stored_text = f.read()
17-
1817
print("## stored text: " + stored_text)
1918
assert stored_text == "sample text 123"
19+
20+
# assert that the Python version as written to python_prefix.txt in the CIBW_BEFORE_ALL step
21+
# is not the same one as is currently running.
22+
with open('python_prefix.txt') as f:
23+
stored_prefix = f.read()
24+
print('stored_prefix', stored_prefix)
25+
print('sys.prefix', sys.prefix)
26+
# Works around path-comparison bugs caused by short-paths on Windows e.g.
27+
# vssadm~1 instead of vssadministrator
28+
assert not os.path.samefile(stored_prefix, sys.prefix)
2029
"""
2130
)
2231
)
@@ -30,21 +39,24 @@ def test(tmp_path):
3039
print("dummy text", file=ff)
3140

3241
# build the wheels
33-
before_all_command = '''python -c "import os;open('{project}/text_info.txt', 'w').write('sample text '+os.environ.get('TEST_VAL', ''))"'''
42+
before_all_command = (
43+
"""python -c "import os, sys;open('{project}/text_info.txt', 'w').write('sample text '+os.environ.get('TEST_VAL', ''))" && """
44+
'''python -c "import sys; open('{project}/python_prefix.txt', 'w').write(sys.prefix)"'''
45+
)
3446
actual_wheels = utils.cibuildwheel_run(
3547
project_dir,
3648
add_env={
3749
# write python version information to a temporary file, this is
3850
# checked in setup.py
3951
"CIBW_BEFORE_ALL": before_all_command,
40-
"CIBW_BEFORE_ALL_LINUX": f'{before_all_command} && python -c "import sys; assert sys.version_info >= (3, 6)"',
52+
"CIBW_BEFORE_ALL_LINUX": f'{before_all_command} && python -c "import sys; assert sys.version_info >= (3, 8)"',
4153
"CIBW_ENVIRONMENT": "TEST_VAL='123'",
4254
},
55+
single_python=True,
4356
)
4457

4558
# also check that we got the right wheels
46-
(project_dir / "text_info.txt").unlink()
47-
expected_wheels = utils.expected_wheels("spam", "0.1.0")
59+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
4860
assert set(actual_wheels) == set(expected_wheels)
4961

5062

@@ -72,7 +84,8 @@ def test_cwd(tmp_path):
7284
"CIBW_BEFORE_ALL": f'''python -c "import os; assert os.getcwd() == {str(project_dir)!r}"''',
7385
"CIBW_BEFORE_ALL_LINUX": '''python -c "import os; assert os.getcwd() == '/project'"''',
7486
},
87+
single_python=True,
7588
)
7689

77-
expected_wheels = utils.expected_wheels("spam", "0.1.0")
90+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
7891
assert set(actual_wheels) == set(expected_wheels)

test/test_before_build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ def test_cwd(tmp_path):
8282
"CIBW_BEFORE_BUILD": f'''python -c "import os; assert os.getcwd() == {str(project_dir)!r}"''',
8383
"CIBW_BEFORE_BUILD_LINUX": '''python -c "import os; assert os.getcwd() == '/project'"''',
8484
},
85+
single_python=True,
8586
)
8687

87-
expected_wheels = utils.expected_wheels("spam", "0.1.0")
88+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
8889
assert set(actual_wheels) == set(expected_wheels)

test/test_build_frontend_args.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ def test_build_frontend_args(tmp_path, capfd, frontend_name):
1616
with pytest.raises(subprocess.CalledProcessError):
1717
utils.cibuildwheel_run(
1818
project_dir,
19-
add_env={
20-
"CIBW_BUILD": "cp311-*",
21-
"CIBW_BUILD_FRONTEND": f"{frontend_name}; args: -h",
22-
},
19+
add_env={"CIBW_BUILD_FRONTEND": f"{frontend_name}; args: -h"},
20+
single_python=True,
2321
)
2422

2523
captured = capfd.readouterr()

test/test_build_skip.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
project_with_skip_asserts = test_projects.new_c_project(
88
setup_py_add=textwrap.dedent(
9-
r"""
10-
# explode if run on PyPyor Python 3.7 (these should be skipped)
9+
rf"""
1110
if sys.implementation.name != "cpython":
1211
raise Exception("Only CPython shall be built")
13-
if sys.version_info[0:2] == (3, 7):
14-
raise Exception("CPython 3.7 should be skipped")
12+
expected_version = {"({}, {})".format(*utils.SINGLE_PYTHON_VERSION)}
13+
if sys.version_info[0:2] != expected_version:
14+
raise Exception("CPython {{}}.{{}} should be skipped".format(*sys.version_info[0:2]))
1515
"""
1616
)
1717
)
@@ -21,17 +21,19 @@ def test(tmp_path):
2121
project_dir = tmp_path / "project"
2222
project_with_skip_asserts.generate(project_dir)
2323

24+
skip = " ".join(
25+
f"cp3{minor}-*" for minor in range(6, 30) if (3, minor) != utils.SINGLE_PYTHON_VERSION
26+
)
27+
2428
# build the wheels
2529
actual_wheels = utils.cibuildwheel_run(
2630
project_dir,
2731
add_env={
2832
"CIBW_BUILD": "cp3*-*",
29-
"CIBW_SKIP": "cp37-*",
33+
"CIBW_SKIP": f"*t-* {skip}",
3034
},
3135
)
3236

33-
# check that we got the right wheels. There should be no PyPy or 3.7.
34-
expected_wheels = [
35-
w for w in utils.expected_wheels("spam", "0.1.0") if ("-cp3" in w) and ("-cp37" not in w)
36-
]
37+
# check that we got the right wheels. There should be a single version of CPython.
38+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
3739
assert set(actual_wheels) == set(expected_wheels)

test/test_container_engine.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ def test_podman(tmp_path, capfd, request):
2121
actual_wheels = utils.cibuildwheel_run(
2222
project_dir,
2323
add_env={
24-
"CIBW_BUILD": "cp310-*{manylinux,musllinux}_x86_64",
24+
"CIBW_ARCHS": "x86_64",
2525
"CIBW_BEFORE_ALL": "echo 'test log statement from before-all'",
2626
"CIBW_CONTAINER_ENGINE": "podman",
2727
},
28+
single_python=True,
2829
)
2930

3031
# check that the expected wheels are produced
3132
expected_wheels = [
32-
w
33-
for w in utils.expected_wheels("spam", "0.1.0")
34-
if ("-cp310-" in w) and ("x86_64" in w) and ("manylinux" in w or "musllinux" in w)
33+
w for w in utils.expected_wheels("spam", "0.1.0", single_python=True) if "x86_64" in w
3534
]
3635
assert set(actual_wheels) == set(expected_wheels)
3736

@@ -51,15 +50,16 @@ def test_create_args(tmp_path, capfd):
5150
actual_wheels = utils.cibuildwheel_run(
5251
project_dir,
5352
add_env={
54-
"CIBW_BUILD": "cp310-manylinux_*",
53+
"CIBW_SKIP": "*-musllinux_*",
5554
"CIBW_BEFORE_ALL": "echo TEST_CREATE_ARGS is set to $TEST_CREATE_ARGS",
5655
"CIBW_CONTAINER_ENGINE": "docker; create_args: --env=TEST_CREATE_ARGS=itworks",
5756
},
57+
single_python=True,
5858
)
5959

60-
expected_wheels = [
61-
w for w in utils.expected_wheels("spam", "0.1.0") if ("cp310-manylinux" in w)
62-
]
60+
expected_wheels = utils.expected_wheels(
61+
"spam", "0.1.0", musllinux_versions=[], single_python=True
62+
)
6363
assert set(actual_wheels) == set(expected_wheels)
6464

6565
captured = capfd.readouterr()

test/test_cpp_standards.py

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -56,76 +56,62 @@
5656
cpp_test_project.files["setup.py"] = jinja2.Template(setup_py_template)
5757
cpp_test_project.files["spam.cpp"] = jinja2.Template(spam_cpp_template)
5858

59-
cpp11_project = cpp_test_project.copy()
60-
cpp11_project.template_context["extra_compile_args"] = (
61-
["/std:c++11"] if utils.platform == "windows" else ["-std=c++11"]
62-
)
63-
cpp11_project.template_context["spam_cpp_top_level_add"] = "#include <array>"
64-
6559

6660
def test_cpp11(tmp_path):
6761
# This test checks that the C++11 standard is supported
6862
project_dir = tmp_path / "project"
69-
63+
cpp11_project = cpp_test_project.copy()
64+
cpp11_project.template_context["extra_compile_args"] = (
65+
["/std:c++11"] if utils.platform == "windows" else ["-std=c++11"]
66+
)
67+
cpp11_project.template_context["spam_cpp_top_level_add"] = "#include <array>"
7068
cpp11_project.generate(project_dir)
7169

72-
actual_wheels = utils.cibuildwheel_run(project_dir)
73-
expected_wheels = list(utils.expected_wheels("spam", "0.1.0"))
70+
actual_wheels = utils.cibuildwheel_run(project_dir, single_python=True)
71+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
7472

7573
assert set(actual_wheels) == set(expected_wheels)
7674

7775

78-
cpp14_project = cpp_test_project.copy()
79-
cpp14_project.template_context["extra_compile_args"] = (
80-
["/std:c++14"] if utils.platform == "windows" else ["-std=c++14"]
81-
)
82-
cpp14_project.template_context["spam_cpp_top_level_add"] = "int a = 100'000;"
83-
84-
8576
def test_cpp14(tmp_path):
8677
# This test checks that the C++14 standard is supported
8778
project_dir = tmp_path / "project"
88-
79+
cpp14_project = cpp_test_project.copy()
80+
cpp14_project.template_context["extra_compile_args"] = (
81+
["/std:c++14"] if utils.platform == "windows" else ["-std=c++14"]
82+
)
83+
cpp14_project.template_context["spam_cpp_top_level_add"] = "int a = 100'000;"
8984
cpp14_project.generate(project_dir)
9085

91-
actual_wheels = utils.cibuildwheel_run(project_dir)
92-
expected_wheels = list(utils.expected_wheels("spam", "0.1.0"))
86+
actual_wheels = utils.cibuildwheel_run(project_dir, single_python=True)
87+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
9388

9489
assert set(actual_wheels) == set(expected_wheels)
9590

9691

97-
cpp17_project = cpp_test_project.copy()
98-
99-
cpp17_project.template_context["extra_compile_args"] = [
100-
"/std:c++17" if utils.platform == "windows" else "-std=c++17"
101-
]
102-
cpp17_project.template_context["spam_cpp_top_level_add"] = r"""
103-
#include <utility>
104-
auto a = std::pair(5.0, false);
105-
"""
106-
107-
10892
def test_cpp17(tmp_path):
10993
# This test checks that the C++17 standard is supported
11094
project_dir = tmp_path / "project"
111-
95+
cpp17_project = cpp_test_project.copy()
96+
cpp17_project.template_context["extra_compile_args"] = [
97+
"/std:c++17" if utils.platform == "windows" else "-std=c++17"
98+
]
99+
cpp17_project.template_context["spam_cpp_top_level_add"] = r"""
100+
#include <utility>
101+
auto a = std::pair(5.0, false);
102+
"""
112103
cpp17_project.generate(project_dir)
113104

114105
if os.environ.get("APPVEYOR_BUILD_WORKER_IMAGE", "") == "Visual Studio 2015":
115106
pytest.skip("Visual Studio 2015 does not support C++17")
116107

117-
# Pypy's distutils sets the default compiler to 'msvc9compiler', which
118-
# is too old to support cpp17.
119-
add_env = {"CIBW_SKIP": "pp*"}
120-
108+
add_env = {}
121109
if utils.platform == "macos":
122110
add_env["MACOSX_DEPLOYMENT_TARGET"] = "10.13"
123111

124-
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env)
125-
expected_wheels = [
126-
w
127-
for w in utils.expected_wheels("spam", "0.1.0", macosx_deployment_target="10.13")
128-
if "-pp" not in w
129-
]
112+
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env, single_python=True)
113+
expected_wheels = utils.expected_wheels(
114+
"spam", "0.1.0", macosx_deployment_target="10.13", single_python=True
115+
)
130116

131117
assert set(actual_wheels) == set(expected_wheels)

test/test_environment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ def test(tmp_path):
4949
"CIBW_ENVIRONMENT": """CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH=$PATH:/opt/cibw_test_path""",
5050
"CIBW_ENVIRONMENT_WINDOWS": f'''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$({python_echo} 'test string 3')" PATH="$PATH;/opt/cibw_test_path"''',
5151
},
52+
single_python=True,
5253
)
5354

5455
# also check that we got the right wheels built
55-
expected_wheels = utils.expected_wheels("spam", "0.1.0")
56+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
5657
assert set(actual_wheels) == set(expected_wheels)
5758

5859

@@ -133,12 +134,12 @@ def test_overridden_pip_constraint(tmp_path, build_frontend):
133134
actual_wheels = utils.cibuildwheel_run(
134135
project_dir,
135136
add_env={
136-
"CIBW_BUILD": "cp312-*",
137137
"CIBW_BUILD_FRONTEND": build_frontend,
138138
"PIP_CONSTRAINT": str(constraints_file),
139139
"CIBW_ENVIRONMENT_LINUX": "PIP_CONSTRAINT=./constraints.txt",
140140
},
141+
single_python=True,
141142
)
142143

143-
expected_wheels = [w for w in utils.expected_wheels("spam", "0.1.0") if "cp312" in w]
144+
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
144145
assert set(actual_wheels) == set(expected_wheels)

0 commit comments

Comments
 (0)