Skip to content

Commit 77c70d7

Browse files
committed
feat: add the start of the templates testing architecture
1 parent e085994 commit 77c70d7

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for cookiecutter-robust-python."""

tests/conftest.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Fixtures used in all tests for cookiecutter-robust-python."""
2+
import json
3+
import os
4+
from pathlib import Path
5+
from typing import Any, Generator
6+
7+
import platformdirs
8+
import pytest
9+
from _pytest.fixtures import FixtureRequest
10+
from _pytest.tmpdir import TempPathFactory
11+
from cookiecutter.main import cookiecutter
12+
13+
14+
pytest_plugins: list[str] = ["pytester"]
15+
16+
17+
REPO_FOLDER: Path = Path(__file__).parent.parent
18+
COOKIECUTTER_FOLDER: Path = REPO_FOLDER / "{{cookiecutter.project_name}}"
19+
HOOKS_FOLDER: Path = REPO_FOLDER / "hooks"
20+
SCRIPTS_FOLDER: Path = REPO_FOLDER / "scripts"
21+
22+
COOKIECUTTER_JSON_PATH: Path = COOKIECUTTER_FOLDER / "cookiecutter.json"
23+
COOKIECUTTER_JSON: dict[str, Any] = json.loads(COOKIECUTTER_JSON_PATH.read_text())
24+
25+
26+
@pytest.fixture(scope="session")
27+
def robust_python_demo_path(tmp_path_factory: TempPathFactory) -> Path:
28+
"""Creates a temporary example python project for testing against and returns its Path."""
29+
demos_path: Path = tmp_path_factory.mktemp("demos")
30+
cookiecutter(
31+
str(REPO_FOLDER),
32+
no_input=True,
33+
overwrite_if_exists=True,
34+
output_dir=demos_path,
35+
extra_context={
36+
"project_name": "robust-python-demo",
37+
"add_rust_extension": False
38+
}
39+
)
40+
return demos_path / "robust-python-demo"
41+
42+
43+
@pytest.fixture(scope="session")
44+
def robust_maturin_demo_path(tmp_path_factory: TempPathFactory) -> Path:
45+
"""Creates a temporary example maturin project for testing against and returns its Path."""
46+
demos_path: Path = tmp_path_factory.mktemp("demos")
47+
cookiecutter(
48+
str(REPO_FOLDER),
49+
no_input=True,
50+
overwrite_if_exists=True,
51+
output_dir=demos_path,
52+
extra_context={
53+
"project_name": "robust-maturin-demo",
54+
"add_rust_extension": True
55+
}
56+
)
57+
return demos_path / "robust-maturin-demo"
58+
59+
60+
@pytest.fixture(scope="function")
61+
def inside_robust_python_demo(robust_python_demo_path: Path) -> Generator[Path, None, None]:
62+
"""Changes the current working directory to the robust-python-demo project."""
63+
original_path: Path = Path.cwd()
64+
os.chdir(robust_python_demo_path)
65+
yield robust_python_demo_path
66+
os.chdir(original_path)
67+
68+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""Integration tests for cookiecutter-robust-python."""
2+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Fixtures used in integration tests for cookiecutter-robust-python."""

0 commit comments

Comments
 (0)