From 79cf7e47aed8721a0b6d9f327b81bac0649fe1c9 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Fri, 28 Feb 2020 19:05:02 +0100 Subject: [PATCH] fix test after rebase, fix typos in readme --- README.md | 2 +- cibuildwheel/linux.py | 2 +- .../cibuildwheel_test.py | 1 + .../setup.py | 1 - .../{10_before_test => 11_before_test}/spam.c | 0 .../test/spam_test.py | 9 +- unit_test/main_options_test.py | 221 ------------------ 7 files changed, 9 insertions(+), 227 deletions(-) rename test/{10_before_test => 11_before_test}/cibuildwheel_test.py (99%) rename test/{10_before_test => 11_before_test}/setup.py (90%) rename test/{10_before_test => 11_before_test}/spam.c (100%) rename test/{10_before_test => 11_before_test}/test/spam_test.py (82%) delete mode 100644 unit_test/main_options_test.py diff --git a/README.md b/README.md index 08159b81..aa843107 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Options | | [`CIBW_BEFORE_TEST`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-test) | Execute shell command to prepare test environment | | | [`CIBW_TEST_REQUIRES`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-requires) | Install Python dependencies before running the tests | | | [`CIBW_TEST_EXTRAS`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-extras) | Install your wheel for testing using extras_require | -| **Other** | [`CIBW_BUILD_VERBOSITY`](https://cibuildwheel.readthedocs.io/en/stable/options/#test-extras) | Increase/decrease the output of pip wheel | +| **Other** | [`CIBW_BUILD_VERBOSITY`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-verbosity) | Increase/decrease the output of pip wheel | Working examples ---------------- diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 39494ef9..3113f309 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -206,7 +206,7 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes environment_exports='\n'.join(environment.as_shell_commands()), uid=os.getuid(), gid=os.getgid(), - before_test=shlex_quote( + before_test=shlex.quote( prepare_command(before_test, project='/project') if before_test else '' ), ) diff --git a/test/10_before_test/cibuildwheel_test.py b/test/11_before_test/cibuildwheel_test.py similarity index 99% rename from test/10_before_test/cibuildwheel_test.py rename to test/11_before_test/cibuildwheel_test.py index f6a56af4..7db1b127 100644 --- a/test/10_before_test/cibuildwheel_test.py +++ b/test/11_before_test/cibuildwheel_test.py @@ -1,6 +1,7 @@ import os import utils + def test(): project_dir = os.path.dirname(__file__) diff --git a/test/10_before_test/setup.py b/test/11_before_test/setup.py similarity index 90% rename from test/10_before_test/setup.py rename to test/11_before_test/setup.py index 7bdeac0b..e3ea2938 100644 --- a/test/10_before_test/setup.py +++ b/test/11_before_test/setup.py @@ -1,5 +1,4 @@ from setuptools import setup, Extension -import sys, os setup( diff --git a/test/10_before_test/spam.c b/test/11_before_test/spam.c similarity index 100% rename from test/10_before_test/spam.c rename to test/11_before_test/spam.c diff --git a/test/10_before_test/test/spam_test.py b/test/11_before_test/test/spam_test.py similarity index 82% rename from test/10_before_test/test/spam_test.py rename to test/11_before_test/test/spam_test.py index f5d9d605..e25cc0c7 100644 --- a/test/10_before_test/test/spam_test.py +++ b/test/11_before_test/test/spam_test.py @@ -1,4 +1,5 @@ -import sys, os +import sys +import os from unittest import TestCase @@ -21,5 +22,7 @@ class TestBeforeTest(TestCase): stored_executable = f.read() print('stored_executable', stored_executable) print('sys.executable', sys.executable) - # windows/mac are case insensitive - assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower() + # Works around path-comparison bugs caused by short-paths on Windows e.g. + # vssadm~1 instead of vssadministrator + + assert os.stat(stored_executable) == os.stat(sys.executable) diff --git a/unit_test/main_options_test.py b/unit_test/main_options_test.py deleted file mode 100644 index 73545d61..00000000 --- a/unit_test/main_options_test.py +++ /dev/null @@ -1,221 +0,0 @@ -import pytest - -import sys - -from cibuildwheel.__main__ import main -from cibuildwheel.environment import ParsedEnvironment -from cibuildwheel.util import BuildSelector - -from main_util_fixtures import mock_protection, fake_project_dir, platform, intercepted_build_args - - - -# CIBW_PLATFORM is tested in main_platform_test.py - - -def test_output_dir(platform, intercepted_build_args, monkeypatch): - OUTPUT_DIR = 'some_output_dir' - - monkeypatch.setenv('CIBW_OUTPUT_DIR', OUTPUT_DIR) - - main() - - assert intercepted_build_args.kwargs['output_dir'] == OUTPUT_DIR - - -def test_output_dir_default(platform, intercepted_build_args, monkeypatch): - main() - - assert intercepted_build_args.kwargs['output_dir'] == 'wheelhouse' - - -@pytest.mark.parametrize('also_set_environment', [False, True]) -def test_output_dir_argument(also_set_environment, platform, intercepted_build_args, monkeypatch): - OUTPUT_DIR = 'some_output_dir' - - monkeypatch.setattr(sys, 'argv', sys.argv + ['--output-dir', OUTPUT_DIR]) - if also_set_environment: - monkeypatch.setenv('CIBW_OUTPUT_DIR', 'not_this_output_dir') - - main() - - assert intercepted_build_args.kwargs['output_dir'] == OUTPUT_DIR - - -def test_build_selector(platform, intercepted_build_args, monkeypatch): - BUILD = 'some build* *-selector' - SKIP = 'some skip* *-selector' - - monkeypatch.setenv('CIBW_BUILD', BUILD) - monkeypatch.setenv('CIBW_SKIP', SKIP) - - main() - - intercepted_build_selector = intercepted_build_args.kwargs['build_selector'] - assert isinstance(intercepted_build_selector, BuildSelector) - assert intercepted_build_selector('build-this') - assert not intercepted_build_selector('skip-that') - # This unit test is just testing the options of 'main' - # Unit tests for BuildSelector are in build_selector_test.py - - -@pytest.mark.parametrize('architecture, image, full_image', [ - ('x86_64', None, 'quay.io/pypa/manylinux2010_x86_64'), - ('x86_64', 'manylinux1', 'quay.io/pypa/manylinux1_x86_64'), - ('x86_64', 'manylinux2010', 'quay.io/pypa/manylinux2010_x86_64'), - ('x86_64', 'manylinux2014', 'quay.io/pypa/manylinux2014_x86_64'), - ('x86_64', 'custom_image', 'custom_image'), - ('i686', None, 'quay.io/pypa/manylinux2010_i686'), - ('i686', 'manylinux1', 'quay.io/pypa/manylinux1_i686'), - ('i686', 'manylinux2010', 'quay.io/pypa/manylinux2010_i686'), - ('i686', 'manylinux2014', 'quay.io/pypa/manylinux2014_i686'), - ('i686', 'custom_image', 'custom_image'), -]) -def test_manylinux_images(architecture, image, full_image, platform, intercepted_build_args, monkeypatch): - if image is not None: - monkeypatch.setenv('CIBW_MANYLINUX_' + architecture.upper() + '_IMAGE', image) - - main() - - if platform == 'linux': - assert intercepted_build_args.kwargs['manylinux_images'][architecture] == full_image - else: - assert 'manylinux_images' not in intercepted_build_args.kwargs - - -def get_default_repair_command(platform): - if platform == 'linux': - return 'auditwheel repair -w {dest_dir} {wheel}' - elif platform == 'macos': - return 'delocate-listdeps {wheel} && delocate-wheel -w {dest_dir} {wheel}' - elif platform == 'windows': - return '' - else: - raise ValueError('Unknown platform', platform) - -@pytest.mark.parametrize('repair_command', [None, 'repair', 'repair -w {dest_dir} {wheel}']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_repair_command(repair_command, platform_specific, platform, intercepted_build_args, monkeypatch): - if repair_command is not None: - if platform_specific: - monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND_' + platform.upper(), repair_command) - monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND', 'overwritten') - else: - monkeypatch.setenv('CIBW_REPAIR_WHEEL_COMMAND', repair_command) - - main() - - expected_repair = repair_command or get_default_repair_command(platform) - assert intercepted_build_args.kwargs['repair_command'] == expected_repair - - -@pytest.mark.parametrize('environment', [ - {}, - {'something': 'value'}, - {'something': 'value', 'something_else': 'other_value'} -]) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_environment(environment, platform_specific, platform, intercepted_build_args, monkeypatch): - env_string = ' '.join(['{}={}'.format(k, v) for k, v in environment.items()]) - if platform_specific: - monkeypatch.setenv('CIBW_ENVIRONMENT_' + platform.upper(), env_string) - monkeypatch.setenv('CIBW_ENVIRONMENT', 'overwritten') - else: - monkeypatch.setenv('CIBW_ENVIRONMENT', env_string) - - main() - - intercepted_environment = intercepted_build_args.kwargs['environment'] - assert isinstance(intercepted_environment, ParsedEnvironment) - assert intercepted_environment.as_dictionary(prev_environment={}) == environment - - -@pytest.mark.parametrize('test_requires', [None, 'requirement other_requirement']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_test_requires(test_requires, platform_specific, platform, intercepted_build_args, monkeypatch): - if test_requires is not None: - if platform_specific: - monkeypatch.setenv('CIBW_TEST_REQUIRES_' + platform.upper(), test_requires) - monkeypatch.setenv('CIBW_TEST_REQUIRES', 'overwritten') - else: - monkeypatch.setenv('CIBW_TEST_REQUIRES', test_requires) - - main() - - assert intercepted_build_args.kwargs['test_requires'] == (test_requires or '').split() - - -@pytest.mark.parametrize('test_extras', [None, 'extras']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_test_extras(test_extras, platform_specific, platform, intercepted_build_args, monkeypatch): - if test_extras is not None: - if platform_specific: - monkeypatch.setenv('CIBW_TEST_EXTRAS_' + platform.upper(), test_extras) - monkeypatch.setenv('CIBW_TEST_EXTRAS', 'overwritten') - else: - monkeypatch.setenv('CIBW_TEST_EXTRAS', test_extras) - - main() - - assert intercepted_build_args.kwargs['test_extras'] == ('[' + test_extras + ']' if test_extras else '') - - -@pytest.mark.parametrize('test_command', [None, 'test --command']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_test_command(test_command, platform_specific, platform, intercepted_build_args, monkeypatch): - if test_command is not None: - if platform_specific: - monkeypatch.setenv('CIBW_TEST_COMMAND_' + platform.upper(), test_command) - monkeypatch.setenv('CIBW_TEST_COMMAND', 'overwritten') - else: - monkeypatch.setenv('CIBW_TEST_COMMAND', test_command) - - main() - - assert intercepted_build_args.kwargs['test_command'] == test_command - - -@pytest.mark.parametrize('before_build', [None, 'before --build']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_before_build(before_build, platform_specific, platform, intercepted_build_args, monkeypatch): - if before_build is not None: - if platform_specific: - monkeypatch.setenv('CIBW_BEFORE_BUILD_' + platform.upper(), before_build) - monkeypatch.setenv('CIBW_BEFORE_BUILD', 'overwritten') - else: - monkeypatch.setenv('CIBW_BEFORE_BUILD', before_build) - - main() - - assert intercepted_build_args.kwargs['before_build'] == before_build - - -@pytest.mark.parametrize('build_verbosity', [None, 0, 2, -2, 4, -4]) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_build_verbosity(build_verbosity, platform_specific, platform, intercepted_build_args, monkeypatch): - if build_verbosity is not None: - if platform_specific: - monkeypatch.setenv('CIBW_BUILD_VERBOSITY_' + platform.upper(), str(build_verbosity)) - monkeypatch.setenv('CIBW_BUILD_VERBOSITY', 'overwritten') - else: - monkeypatch.setenv('CIBW_BUILD_VERBOSITY', str(build_verbosity)) - - main() - - expected_verbosity = max(-3, min(3, int(build_verbosity or 0))) - assert intercepted_build_args.kwargs['build_verbosity'] == expected_verbosity - - -@pytest.mark.parametrize('before_test', ["", 'before --test']) -@pytest.mark.parametrize('platform_specific', [False, True]) -def test_before_test(before_test, platform_specific, platform, intercepted_build_args, monkeypatch): - if before_test is not None: - if platform_specific: - monkeypatch.setenv('CIBW_BEFORE_TEST_' + platform.upper(), before_test) - monkeypatch.setenv('CIBW_BEFORE_TEST', 'overwritten') - else: - monkeypatch.setenv('CIBW_BEFORE_TEST', before_test) - - main() - - assert intercepted_build_args.kwargs['before_test'] == before_test