| 1 |
import os |
| 2 |
import shutil |
| 3 |
import sys |
| 4 |
from collections.abc import Generator |
| 5 |
from contextlib import contextmanager |
| 6 |
from pathlib import Path |
| 7 |
|
| 8 |
import pytest |
| 9 |
from typer.testing import CliRunner |
| 10 |
|
| 11 |
skip_on_windows = pytest.mark.skipif( |
| 12 |
sys.platform == "win32", reason="Skipping on Windows" |
| 13 |
) |
| 14 |
|
| 15 |
|
| 16 |
THIS_DIR = Path(__file__).parent.resolve() |
| 17 |
|
| 18 |
|
| 19 |
def pytest_collection_modifyitems(config, items: list[pytest.Item]) -> None: |
| 20 |
if sys.platform != "win32": |
| 21 |
return |
| 22 |
|
| 23 |
for item in items: |
| 24 |
item_path = Path(item.fspath).resolve() |
| 25 |
if item_path.is_relative_to(THIS_DIR): |
| 26 |
item.add_marker(skip_on_windows) |
| 27 |
|
| 28 |
|
| 29 |
@contextmanager |
| 30 |
def changing_dir(directory: str | Path) -> Generator[None, None, None]: |
| 31 |
initial_dir = os.getcwd() |
| 32 |
os.chdir(directory) |
| 33 |
try: |
| 34 |
yield |
| 35 |
finally: |
| 36 |
os.chdir(initial_dir) |
| 37 |
|
| 38 |
|
| 39 |
@pytest.fixture(name="runner") |
| 40 |
def get_runner(tmp_path: Path): |
| 41 |
with changing_dir(tmp_path): |
| 42 |
yield CliRunner() |
| 43 |
|
| 44 |
|
| 45 |
@pytest.fixture(name="root_dir") |
| 46 |
def prepare_paths(runner): |
| 47 |
docs_dir = Path("docs") |
| 48 |
en_docs_dir = docs_dir / "en" / "docs" |
| 49 |
lang_docs_dir = docs_dir / "lang" / "docs" |
| 50 |
en_docs_dir.mkdir(parents=True, exist_ok=True) |
| 51 |
lang_docs_dir.mkdir(parents=True, exist_ok=True) |
| 52 |
yield Path.cwd() |
| 53 |
|
| 54 |
|
| 55 |
@pytest.fixture |
| 56 |
def copy_test_files(root_dir: Path, request: pytest.FixtureRequest): |
| 57 |
en_file_path = Path(request.param[0]) |
| 58 |
translation_file_path = Path(request.param[1]) |
| 59 |
shutil.copy(str(en_file_path), str(root_dir / "docs" / "en" / "docs" / "doc.md")) |
| 60 |
shutil.copy( |
| 61 |
str(translation_file_path), str(root_dir / "docs" / "lang" / "docs" / "doc.md") |
| 62 |
) |