2026-04-01 10:23:02 -04:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
2021-01-06 13:50:58 -05:00
|
|
|
from . import test_projects, utils
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
before_test_project = test_projects.new_c_project()
|
2023-10-27 01:21:20 -04:00
|
|
|
before_test_project.files["test/spam_test.py"] = r"""
|
2020-05-02 16:54:19 +01:00
|
|
|
import sys
|
|
|
|
|
import os
|
2024-05-26 12:40:11 +02:00
|
|
|
from pathlib import Path
|
2020-05-02 16:54:19 +01:00
|
|
|
from unittest import TestCase
|
|
|
|
|
|
2025-04-29 00:25:17 +02:00
|
|
|
PROJECT_DIR = Path(__file__).parent.parent.resolve()
|
2024-05-26 12:40:11 +02:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
class TestBeforeTest(TestCase):
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_version(self) -> None:
|
2024-02-29 22:27:09 +01:00
|
|
|
# assert that the Python version as written to pythonversion_bt.txt in the CIBW_BEFORE_TEST step
|
2020-05-02 16:54:19 +01:00
|
|
|
# is the same one as is currently running.
|
|
|
|
|
# because of use symlinks in MacOS run this test is also need
|
2024-05-26 12:40:11 +02:00
|
|
|
stored_version = PROJECT_DIR.joinpath('pythonversion_bt.txt').read_text()
|
2020-05-02 16:54:19 +01:00
|
|
|
print('stored_version', stored_version)
|
|
|
|
|
print('sys.version', sys.version)
|
|
|
|
|
assert stored_version == sys.version
|
|
|
|
|
|
2026-04-01 10:23:02 -04:00
|
|
|
def test_prefix(self) -> None:
|
2020-05-02 16:54:19 +01:00
|
|
|
# check that the prefix also was written
|
2024-05-26 12:40:11 +02:00
|
|
|
stored_prefix = PROJECT_DIR.joinpath('pythonprefix_bt.txt').read_text()
|
2020-05-02 16:54:19 +01:00
|
|
|
print('stored_prefix', stored_prefix)
|
|
|
|
|
print('sys.prefix', sys.prefix)
|
|
|
|
|
# Works around path-comparison bugs caused by short-paths on Windows e.g.
|
|
|
|
|
# vssadm~1 instead of vssadministrator
|
|
|
|
|
|
2024-05-26 12:40:11 +02:00
|
|
|
assert os.path.samefile(stored_prefix, sys.prefix)
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2020-05-02 22:50:52 +01:00
|
|
|
|
2026-04-01 10:23:02 -04:00
|
|
|
def test(tmp_path: Path, build_frontend_env: dict[str, str]) -> None:
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 16:54:19 +01:00
|
|
|
before_test_project.generate(project_dir)
|
2021-05-03 11:45:43 -04:00
|
|
|
test_project_dir = project_dir / "dependency"
|
2020-12-31 17:50:19 +01:00
|
|
|
test_projects.new_c_project().generate(test_project_dir)
|
2020-05-02 16:54:19 +01:00
|
|
|
|
2024-05-28 05:31:36 -07:00
|
|
|
before_test_steps = [
|
2025-04-29 00:25:17 +02:00
|
|
|
'''python -c "import pathlib, sys; pathlib.Path('{project}/pythonversion_bt.txt').write_text(sys.version)"''',
|
|
|
|
|
'''python -c "import pathlib, sys; pathlib.Path('{project}/pythonprefix_bt.txt').write_text(sys.prefix)"''',
|
2024-05-28 05:31:36 -07:00
|
|
|
]
|
|
|
|
|
|
2025-05-16 11:11:16 +01:00
|
|
|
if utils.get_platform() == "pyodide":
|
2024-05-28 05:31:36 -07:00
|
|
|
before_test_steps.extend(
|
|
|
|
|
["pyodide build {project}/dependency", "pip install --find-links dist/ spam"]
|
|
|
|
|
)
|
2024-06-17 07:07:35 +02:00
|
|
|
elif build_frontend_env["CIBW_BUILD_FRONTEND"] in {"pip", "build"}:
|
2024-05-28 05:31:36 -07:00
|
|
|
before_test_steps.append("python -m pip install {project}/dependency")
|
|
|
|
|
|
|
|
|
|
before_test = " && ".join(before_test_steps)
|
2024-05-26 12:40:11 +02:00
|
|
|
|
2020-05-02 16:54:19 +01:00
|
|
|
# build the wheels
|
2021-04-30 17:56:34 -04:00
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
|
|
|
project_dir,
|
|
|
|
|
add_env={
|
|
|
|
|
# write python version information to a temporary file, this is
|
|
|
|
|
# checked in setup.py
|
2024-05-26 12:40:11 +02:00
|
|
|
"CIBW_BEFORE_TEST": before_test,
|
2021-05-29 00:26:55 +02:00
|
|
|
"CIBW_TEST_REQUIRES": "pytest",
|
2021-04-30 17:56:34 -04:00
|
|
|
# the 'false ||' bit is to ensure this command runs in a shell on
|
|
|
|
|
# mac/linux.
|
2025-05-28 16:05:16 +01:00
|
|
|
"CIBW_TEST_COMMAND": f"false || {utils.invoke_pytest()} {{project}}/test",
|
2025-07-31 06:31:23 +02:00
|
|
|
"CIBW_TEST_COMMAND_WINDOWS": "pytest {project}/test",
|
2024-06-17 07:07:35 +02:00
|
|
|
**build_frontend_env,
|
2021-04-30 17:56:34 -04:00
|
|
|
},
|
|
|
|
|
)
|
2020-05-02 16:54:19 +01:00
|
|
|
|
|
|
|
|
# also check that we got the right wheels
|
2021-05-03 11:45:43 -04:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0")
|
2020-05-02 16:54:19 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|