2020-06-18 02:00:30 +02:00
|
|
|
from pathlib import Path
|
2020-05-03 14:09:47 +01:00
|
|
|
|
|
|
|
|
import jinja2
|
|
|
|
|
|
2020-05-02 22:42:35 +01:00
|
|
|
from . import utils
|
2020-05-17 16:54:33 +01:00
|
|
|
from .test_projects import TestProject
|
|
|
|
|
from .test_projects.c import SPAM_C_TEMPLATE
|
2020-04-10 17:42:39 +01:00
|
|
|
|
2020-05-17 16:54:33 +01:00
|
|
|
subdir_package_project = TestProject()
|
2020-05-02 21:00:58 +01:00
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
subdir_package_project.files["src/spam/spam.c"] = jinja2.Template(SPAM_C_TEMPLATE)
|
|
|
|
|
subdir_package_project.template_context["spam_c_top_level_add"] = ""
|
|
|
|
|
subdir_package_project.template_context["spam_c_function_add"] = ""
|
2020-05-02 21:00:58 +01:00
|
|
|
|
2023-10-27 01:21:20 -04:00
|
|
|
subdir_package_project.files["src/spam/setup.py"] = r"""
|
2020-05-02 21:00:58 +01:00
|
|
|
from setuptools import Extension, setup
|
|
|
|
|
|
|
|
|
|
setup(
|
|
|
|
|
name="spam",
|
|
|
|
|
ext_modules=[Extension('spam', sources=['spam.c'])],
|
|
|
|
|
version="0.1.0",
|
|
|
|
|
)
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2020-05-02 21:00:58 +01:00
|
|
|
|
2023-10-27 01:21:20 -04:00
|
|
|
subdir_package_project.files["src/spam/test/run_tests.py"] = r"""
|
2020-05-02 21:00:58 +01:00
|
|
|
print('run_tests.py executed!')
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2020-05-02 21:00:58 +01:00
|
|
|
|
2023-10-27 01:21:20 -04:00
|
|
|
subdir_package_project.files["bin/before_build.py"] = r"""
|
2020-05-02 21:00:58 +01:00
|
|
|
print('before_build.py executed!')
|
2021-05-03 11:45:43 -04:00
|
|
|
"""
|
2020-04-10 17:42:39 +01:00
|
|
|
|
|
|
|
|
|
2020-05-03 14:08:57 +01:00
|
|
|
def test(capfd, tmp_path):
|
2021-05-03 11:45:43 -04:00
|
|
|
project_dir = tmp_path / "project"
|
2020-05-02 21:00:58 +01:00
|
|
|
subdir_package_project.generate(project_dir)
|
|
|
|
|
|
2021-05-03 11:45:43 -04:00
|
|
|
package_dir = Path("src", "spam")
|
2020-04-10 17:42:39 +01:00
|
|
|
# build the wheels
|
2021-04-30 17:56:34 -04:00
|
|
|
actual_wheels = utils.cibuildwheel_run(
|
|
|
|
|
project_dir,
|
|
|
|
|
package_dir=package_dir,
|
|
|
|
|
add_env={
|
2021-05-03 11:45:43 -04:00
|
|
|
"CIBW_BEFORE_BUILD": "python {project}/bin/before_build.py",
|
|
|
|
|
"CIBW_TEST_COMMAND": "python {package}/test/run_tests.py",
|
2021-04-30 17:56:34 -04:00
|
|
|
},
|
2024-05-26 12:41:20 +02:00
|
|
|
single_python=True,
|
2021-04-30 17:56:34 -04:00
|
|
|
)
|
2020-04-10 17:42:39 +01:00
|
|
|
|
|
|
|
|
# check that the expected wheels are produced
|
2024-05-26 12:41:20 +02:00
|
|
|
expected_wheels = utils.expected_wheels("spam", "0.1.0", single_python=True)
|
2020-04-10 17:42:39 +01:00
|
|
|
assert set(actual_wheels) == set(expected_wheels)
|
2020-04-12 23:15:49 +01:00
|
|
|
|
|
|
|
|
captured = capfd.readouterr()
|
|
|
|
|
assert "before_build.py executed!" in captured.out
|
|
|
|
|
assert "run_tests.py executed!" in captured.out
|