Fix paths in unit tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -18,7 +19,7 @@ class ArgsInterceptor:
|
||||
self.kwargs = kwargs
|
||||
|
||||
|
||||
MOCK_PACKAGE_DIR = 'some_package_dir'
|
||||
MOCK_PACKAGE_DIR = Path('some_package_dir')
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -43,16 +44,16 @@ def fake_package_dir(monkeypatch):
|
||||
'''
|
||||
Monkey-patch enough for the main() function to run
|
||||
'''
|
||||
real_os_path_exists = os.path.exists
|
||||
real_path_exists = Path.exists
|
||||
|
||||
def mock_os_path_exists(path):
|
||||
if path == os.path.join(MOCK_PACKAGE_DIR, 'setup.py'):
|
||||
def mock_path_exists(path):
|
||||
if path == MOCK_PACKAGE_DIR / 'setup.py':
|
||||
return True
|
||||
else:
|
||||
return real_os_path_exists(path)
|
||||
return real_path_exists(path)
|
||||
|
||||
monkeypatch.setattr(os.path, 'exists', mock_os_path_exists)
|
||||
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', MOCK_PACKAGE_DIR])
|
||||
monkeypatch.setattr(Path, 'exists', mock_path_exists)
|
||||
monkeypatch.setattr(sys, 'argv', ['cibuildwheel', str(MOCK_PACKAGE_DIR)])
|
||||
|
||||
|
||||
@pytest.fixture(params=['linux', 'macos', 'windows'])
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
from fnmatch import fnmatch
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -12,9 +13,9 @@ from cibuildwheel.util import BuildSelector
|
||||
|
||||
|
||||
def test_output_dir(platform, intercepted_build_args, monkeypatch):
|
||||
OUTPUT_DIR = 'some_output_dir'
|
||||
OUTPUT_DIR = Path('some_output_dir')
|
||||
|
||||
monkeypatch.setenv('CIBW_OUTPUT_DIR', OUTPUT_DIR)
|
||||
monkeypatch.setenv('CIBW_OUTPUT_DIR', str(OUTPUT_DIR))
|
||||
|
||||
main()
|
||||
|
||||
@@ -24,14 +25,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.args[0].output_dir == 'wheelhouse'
|
||||
assert intercepted_build_args.args[0].output_dir == 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 = 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')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user