11from __future__ import annotations
22
33import subprocess
4+ import sys
45import textwrap
56
67import pytest
1415 # is the same one as is currently running.
1516 with open("text_info.txt") as f:
1617 stored_text = f.read()
17-
1818 print("## stored text: " + stored_text)
19- assert stored_text == "sample text 123"
19+ parts = stored_text.split("+")
20+ assert len(parts) == 3
21+ assert parts[0] == "cpython"
22+ if sys.implementation.name == "cpython":
23+ assert sys.hexversion != int(parts[1])
24+ assert parts[2] == "sample text 123"
2025 """
2126 )
2227)
@@ -29,22 +34,38 @@ def test(tmp_path):
2934 with (project_dir / "text_info.txt" ).open (mode = "w" ) as ff :
3035 print ("dummy text" , file = ff )
3136
37+ # we want to limit the number of builds to speed-up tests
38+ builds = ["pp310" ] # always one version of PyPy
39+ if utils .platform == "linux" :
40+ # Linux uses cp38 as a global python
41+ builds .append ("cp312" )
42+ else :
43+ # use a CPython version that's not running cibuildwheel
44+ for minor in range (12 , 8 , - 1 ):
45+ if (3 , minor ) != sys .version_info [:2 ]:
46+ builds .append (f"cp3{ minor } " )
47+ break
48+ assert len (builds ) == 2
49+
3250 # 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', ''))"'''
51+ before_all_command = '''python -ISc "import os, sys ;open('{project}/text_info.txt', 'w').write(f'{sys.implementation.name}+{sys.hexversion}+ sample text '+os.environ.get('TEST_VAL', ''))"'''
3452 actual_wheels = utils .cibuildwheel_run (
3553 project_dir ,
3654 add_env = {
55+ "CIBW_BUILD" : " " .join (f"{ build } -*" for build in builds ),
3756 # write python version information to a temporary file, this is
3857 # checked in setup.py
3958 "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)"' ,
59+ "CIBW_BEFORE_ALL_LINUX" : f'{ before_all_command } && python -ISc "import sys; assert sys.version_info >= (3, 6)"' ,
4160 "CIBW_ENVIRONMENT" : "TEST_VAL='123'" ,
4261 },
4362 )
4463
4564 # also check that we got the right wheels
4665 (project_dir / "text_info.txt" ).unlink ()
47- expected_wheels = utils .expected_wheels ("spam" , "0.1.0" )
66+ expected_wheels = [
67+ w for w in utils .expected_wheels ("spam" , "0.1.0" ) if any (build in w for build in builds )
68+ ]
4869 assert set (actual_wheels ) == set (expected_wheels )
4970
5071
0 commit comments