Skip to content

Commit

Permalink
Testing first batch of os.path -> pathlib
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickJadoul committed Feb 3, 2020
1 parent c78f5c3 commit f9f3e86
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
8 changes: 4 additions & 4 deletions bin/run_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python3

import os, sys, subprocess, shutil
import pathlib, sys, subprocess, shutil


def single_run(test_project):
# run the test
subprocess.check_call(
[sys.executable, '-m', 'pytest', '-vv', os.path.join(test_project, 'cibuildwheel_test.py')],
[sys.executable, '-m', 'pytest', '-vv', test_project / 'cibuildwheel_test.py']
)


Expand All @@ -17,9 +17,9 @@ def single_run(test_project):
parser.add_argument("test_project_dir")
args = parser.parse_args()

project_path = os.path.abspath(args.test_project_dir)
project_path = pathlib.Path(args.test_project_dir).absolute()

if not os.path.exists(project_path):
if not project_path.exists():
print('No test project not found.', file=sys.stderr)
exit(2)

Expand Down
7 changes: 4 additions & 3 deletions bin/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3

import os, sys, subprocess, shutil, json
import os, pathlib, sys, subprocess, shutil, json
from glob import glob

if __name__ == '__main__':
# move cwd to the project root
os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
this_path = pathlib.Path(__file__).absolute()
os.chdir(this_path.parents[1])

### run the unit tests

Expand All @@ -21,7 +22,7 @@

print('Testing projects:', test_projects)

run_test_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'run_test.py')
run_test_path = this_path.parent / 'run_test.py'
for project_path in test_projects:
subprocess.check_call([sys.executable, run_test_path, project_path])

Expand Down
12 changes: 6 additions & 6 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse, os, subprocess, sys, textwrap
import argparse, os, pathlib, subprocess, sys, textwrap

import cibuildwheel
import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos
Expand Down Expand Up @@ -85,11 +85,11 @@ def main():
exit(2)


output_dir = args.output_dir
output_dir = pathlib.Path(args.output_dir)
test_command = get_option_from_environment('CIBW_TEST_COMMAND', platform=platform)
test_requires = get_option_from_environment('CIBW_TEST_REQUIRES', platform=platform, default='').split()
test_extras = get_option_from_environment('CIBW_TEST_EXTRAS', platform=platform, default='')
project_dir = args.project_dir
project_dir = pathlib.Path(args.project_dir)
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
build_verbosity = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='')
build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '')
Expand Down Expand Up @@ -124,7 +124,7 @@ def main():
# This needs to be passed on to the docker container in linux.py
os.environ['CIBUILDWHEEL'] = '1'

if not os.path.exists(os.path.join(project_dir, 'setup.py')):
if not (project_dir / 'setup.py').exists():
print('cibuildwheel: Could not find setup.py at root of project', file=sys.stderr)
exit(2)

Expand Down Expand Up @@ -170,8 +170,8 @@ def main():

print_preamble(platform, build_options)

if not os.path.exists(output_dir):
os.makedirs(output_dir)
if not output_dir.exists():
output_dir.mkdir(parents=True)

if platform == 'linux':
cibuildwheel.linux.build(**build_options)
Expand Down
12 changes: 6 additions & 6 deletions unit_test/main_options_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

import sys
import pathlib, sys

from cibuildwheel.__main__ import main
from cibuildwheel.environment import ParsedEnvironment
Expand All @@ -14,9 +14,9 @@


def test_output_dir(platform, intercepted_build_args, monkeypatch):
OUTPUT_DIR = 'some_output_dir'
OUTPUT_DIR = pathlib.Path('some_output_dir')

monkeypatch.setenv('CIBW_OUTPUT_DIR', OUTPUT_DIR)
monkeypatch.setenv('CIBW_OUTPUT_DIR', str(OUTPUT_DIR))

main()

Expand All @@ -26,14 +26,14 @@ def test_output_dir(platform, intercepted_build_args, monkeypatch):
def test_output_dir_default(platform, intercepted_build_args, monkeypatch):
main()

assert intercepted_build_args.kwargs['output_dir'] == 'wheelhouse'
assert intercepted_build_args.kwargs['output_dir'] == pathlib.Path('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'
OUTPUT_DIR = pathlib.Path('some_output_dir')

monkeypatch.setattr(sys, 'argv', sys.argv + ['--output-dir', OUTPUT_DIR])
monkeypatch.setattr(sys, 'argv', sys.argv + ['--output-dir', str(OUTPUT_DIR)])
if also_set_environment:
monkeypatch.setenv('CIBW_OUTPUT_DIR', 'not_this_output_dir')

Expand Down
17 changes: 13 additions & 4 deletions unit_test/main_util_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest

import sys
import os
import pathlib
import subprocess
import sys

from cibuildwheel import linux, macos, windows, util

Expand All @@ -13,7 +14,7 @@ def __call__(self, *args, **kwargs):
self.kwargs = kwargs


MOCK_PROJECT_DIR = 'some_project_dir'
MOCK_PROJECT_DIR = pathlib.Path('some_project_dir')

@pytest.fixture(autouse=True)
def mock_protection(monkeypatch):
Expand All @@ -39,13 +40,21 @@ def fake_project_dir(monkeypatch):

real_os_path_exists = os.path.exists
def mock_os_path_exists(path):
if path == os.path.join(MOCK_PROJECT_DIR, 'setup.py'):
if path == str(MOCK_PROJECT_DIR / 'setup.py'):
return True
else:
return real_os_path_exists(path)

real_pathlib_path_exists = pathlib.Path.exists
def mock_pathlib_path_exists(path):
if path == MOCK_PROJECT_DIR / 'setup.py':
return True
else:
return real_pathlib_path_exists(path)

monkeypatch.setattr(os.path, 'exists', mock_os_path_exists)
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', MOCK_PROJECT_DIR])
monkeypatch.setattr(pathlib.Path, 'exists', mock_pathlib_path_exists)
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', str(MOCK_PROJECT_DIR)])


@pytest.fixture(params=['linux', 'macos', 'windows'])
Expand Down

0 comments on commit f9f3e86

Please sign in to comment.