Skip to content

Commit b512fe8

Browse files
committed
Utility
1 parent 84aea42 commit b512fe8

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cppython/utility/filesystem.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Helpers for working with the filesystem."""
2+
3+
import os
4+
from collections.abc import Generator
5+
from contextlib import contextmanager
6+
from pathlib import Path
7+
8+
9+
@contextmanager
10+
def isolated_filesystem() -> Generator[Path]:
11+
"""Change the current working directory to the given path for the duration of the test."""
12+
old_cwd = os.getcwd()
13+
os.chdir(path)
14+
try:
15+
yield
16+
finally:
17+
os.chdir(old_cwd)

tests/integration/examples/test_pdm_vcpkg_cmake.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
All examples can be run with the CPPython entry-point, and we use the examples as the test data for the CLI.
44
"""
55

6+
import shutil
67
from pathlib import Path
78

8-
pytest_plugins = ['tests.fixtures.example']
9+
from cppython.utility.filesystem import isolated_filesystem
10+
11+
pytest_plugins = ['tests.fixtures.utility']
912

1013

1114
class TestSetup:
@@ -20,7 +23,7 @@ def test_example_directory(example_directory: Path) -> None:
2023
@staticmethod
2124
def test_list(example_directory: Path) -> None:
2225
"""Verifies that the list command functions with CPPython hooks"""
23-
with runner.isolated_filesystem() as temp_directory:
26+
with isolated_filesystem() as temp_directory:
2427
shutil.copytree(example_directory, temp_directory, dirs_exist_ok=True)
2528

2629
result = runner.invoke(app, ['list'])

0 commit comments

Comments
 (0)