Skip to content

Commit

Permalink
Extend tests and add tests for CIBW_BEFORE_ALL
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickJadoul committed Jul 21, 2020
1 parent f81c947 commit f4578eb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
31 changes: 28 additions & 3 deletions test/test_before_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pytest
import subprocess
import textwrap

from . import utils
Expand All @@ -21,7 +22,7 @@ def test(tmp_path):
project_dir = tmp_path / 'project'
project_with_before_build_asserts.generate(project_dir)

with open(os.path.join(project_dir, "text_info.txt"), mode='w') as ff:
with (project_dir / 'text_info.txt').open(mode='w') as ff:
print("dummy text", file=ff)

# build the wheels
Expand All @@ -33,6 +34,30 @@ def test(tmp_path):
})

# also check that we got the right wheels
os.remove(os.path.join(project_dir, "text_info.txt"))
(project_dir / 'text_info.txt').unlink()
expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels)


def test_failing_command(tmp_path):
project_dir = tmp_path / 'project'
test_projects.new_c_project().generate(project_dir)

with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run(project_dir, add_env={
'CIBW_BEFORE_ALL': 'false',
'CIBW_BEFORE_ALL_WINDOWS': 'exit /b 1',
})


def test_cwd(tmp_path):
project_dir = tmp_path / 'project'
test_projects.new_c_project().generate(project_dir)

actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
'CIBW_BEFORE_ALL': f'''python -c "import os; assert os.getcwd() == {project_dir!r}"''',
'CIBW_BEFORE_ALL_LINUX': '''python -c "import os; assert os.getcwd() == '/project'"''',
})

expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels)
35 changes: 27 additions & 8 deletions test/test_before_build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest
import subprocess
import textwrap

from . import utils
Expand All @@ -24,12 +26,6 @@
print('sys.executable', sys.executable)
# windows/mac are case insensitive
assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower()
if sys.platform == 'linux':
cwd_file = '/tmp/cwd.txt'
with open(cwd_file) as f:
stored_cwd = f.read()
assert stored_cwd == '/project'
''')
)

Expand All @@ -39,8 +35,7 @@ def test(tmp_path):
project_with_before_build_asserts.generate(project_dir)

before_build = ('''python -c "import sys; open('{output_dir}pythonversion.txt', 'w').write(sys.version)" && '''
'''python -c "import sys; open('{output_dir}pythonexecutable.txt', 'w').write(sys.executable)" && '''
'''python -c "import os; open('{output_dir}cwd.txt', 'w').write(os.getcwd())"''')
'''python -c "import sys; open('{output_dir}pythonexecutable.txt', 'w').write(sys.executable)"''')

# build the wheels
actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
Expand All @@ -53,3 +48,27 @@ def test(tmp_path):
# also check that we got the right wheels
expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels)


def test_failing_command(tmp_path):
project_dir = tmp_path / 'project'
test_projects.new_c_project().generate(project_dir)

with pytest.raises(subprocess.CalledProcessError):
utils.cibuildwheel_run(project_dir, add_env={
'CIBW_BEFORE_BUILD': 'false',
'CIBW_BEFORE_BUILD_WINDOWS': 'exit /b 1',
})


def test_cwd(tmp_path):
project_dir = tmp_path / 'project'
test_projects.new_c_project().generate(project_dir)

actual_wheels = utils.cibuildwheel_run(project_dir, add_env={
'CIBW_BEFORE_BUILD': f'''python -c "import os; assert os.getcwd() == {project_dir!r}"''',
'CIBW_BEFORE_BUILD_LINUX': '''python -c "import os; assert os.getcwd() == '/project'"''',
})

expected_wheels = utils.expected_wheels('spam', '0.1.0')
assert set(actual_wheels) == set(expected_wheels)

0 comments on commit f4578eb

Please sign in to comment.