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()
|
2021-04-30 17:56:34 -04:00
|
|
|
before_test_project.files[
|
2021-05-03 11:45:43 -04:00
|
|
|
"test/spam_test.py"
|
|
|
|
|
] = r"""
|
2020-05-02 16:54:19 +01:00
|
|
|
import sys
|
|
|
|
|
import os
|
|
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestBeforeTest(TestCase):
|
|
|
|
|
def test_version(self):
|
|
|
|
|
# assert that the Python version as written to pythonversion.txt in the CIBW_BEFORE_TEST step
|
|
|
|
|
# is the same one as is currently running.
|
|
|
|
|
# because of use symlinks in MacOS run this test is also need
|
|
|
|
|
version_file = 'c:\\pythonversion.txt' if sys.platform == 'win32' else '/tmp/pythonversion.txt'
|
|
|
|
|
with open(version_file) as f:
|
|
|
|
|
stored_version = f.read()
|
|
|
|
|
print('stored_version', stored_version)
|
|
|
|
|
print('sys.version', sys.version)
|
|
|
|
|
assert stored_version == sys.version
|
|
|
|
|
|
|
|
|
|
def test_prefix(self):
|
|
|
|
|
# check that the prefix also was written
|
|
|
|
|
prefix_file = 'c:\\pythonprefix.txt' if sys.platform == 'win32' else '/tmp/pythonprefix.txt'
|
|
|
|
|
with open(prefix_file) as f:
|
|
|
|
|
stored_prefix = f.read()
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
assert os.stat(stored_prefix) == os.stat(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
|
|
|
|
2020-05-03 14:08:57 +01:00
|
|
|
def test(tmp_path):
|
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
|
|
|
|
|
|
|
|
# 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
|
2021-05-03 11:45:43 -04:00
|
|
|
"CIBW_BEFORE_TEST": """python -c "import sys; open('/tmp/pythonversion.txt', 'w').write(sys.version)" && python -c "import sys; open('/tmp/pythonprefix.txt', 'w').write(sys.prefix)" && python -m pip install {project}/dependency""",
|
|
|
|
|
"CIBW_BEFORE_TEST_WINDOWS": """python -c "import sys; open('c:\\pythonversion.txt', 'w').write(sys.version)" && python -c "import sys; open('c:\\pythonprefix.txt', 'w').write(sys.prefix)" && python -m pip install {project}/dependency""",
|
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.
|
2021-05-29 00:26:55 +02:00
|
|
|
"CIBW_TEST_COMMAND": "false || pytest {project}/test",
|
|
|
|
|
"CIBW_TEST_COMMAND_WINDOWS": "pytest {project}/test",
|
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)
|