Skip to content

Commit aa0918a

Browse files
committed
feat: swap to cruft and add basic github actions syntax unit tests
1 parent 12b6d5e commit aa0918a

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
@nox.session(name="generate-demo", python=DEFAULT_TEMPLATE_PYTHON_VERSION)
5050
def generate_demo(session: Session) -> None:
5151
"""Generates a project demo using the cookiecutter-robust-python template."""
52-
session.install("cookiecutter", "platformdirs", "loguru", "typer")
52+
session.install("cookiecutter", "cruft", "platformdirs", "loguru", "typer")
5353
session.run("python", GENERATE_DEMO_SCRIPT, *GENERATE_DEMO_OPTIONS, *session.posargs)
5454

5555

scripts/util.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Callable
1212
from typing import Generator
1313

14+
import cruft
1415
import typer
1516
from cookiecutter.main import cookiecutter
1617
from cookiecutter.utils import work_in
@@ -78,12 +79,12 @@ def generate_demo(
7879
demos_cache_folder.mkdir(exist_ok=True)
7980
if no_cache:
8081
_remove_existing_demo(demo_path=demos_cache_folder / demo_name)
81-
cookiecutter(
82-
template=str(repo_folder),
83-
no_input=True,
82+
cruft.create(
83+
template_git_url=str(repo_folder),
84+
output_dir=demos_cache_folder,
8485
extra_context={"project_name": demo_name, **kwargs},
85-
overwrite_if_exists=True,
86-
output_dir=str(demos_cache_folder),
86+
no_input=True,
87+
overwrite_if_exists=True
8788
)
8889
return demos_cache_folder / demo_name
8990

tests/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Any
66

77
import pytest
8+
import toml
9+
import yaml
810
from _pytest.fixtures import FixtureRequest
911
from _pytest.tmpdir import TempPathFactory
1012
from cookiecutter.main import cookiecutter
@@ -21,6 +23,32 @@ def demos_folder(tmp_path_factory: TempPathFactory) -> Path:
2123
return tmp_path_factory.mktemp("demos")
2224

2325

26+
@pytest.fixture(scope="session")
27+
def robust_yaml(request: FixtureRequest, robust_file: str) -> dict[str, Any]:
28+
return getattr(request, "param", yaml.safe_load(robust_file))
29+
30+
31+
@pytest.fixture(scope="session")
32+
def robust_toml(request: FixtureRequest, robust_file: str) -> dict[str, Any]:
33+
return getattr(request, "param", toml.load(robust_file))
34+
35+
36+
@pytest.fixture(scope="session")
37+
def robust_file(request: FixtureRequest, robust_file__path: Path) -> str:
38+
text: str = robust_file__path.read_text()
39+
return getattr(request, "param", text)
40+
41+
42+
@pytest.fixture(scope="session")
43+
def robust_file__path(request: FixtureRequest, robust_demo: Path, robust_file__path__relative: str) -> Path:
44+
return getattr(request, "param", robust_demo / robust_file__path__relative)
45+
46+
47+
@pytest.fixture(scope="session")
48+
def robust_file__path__relative(request: FixtureRequest) -> str:
49+
return getattr(request, "param", "./pyproject.toml")
50+
51+
2452
@pytest.fixture(scope="session")
2553
def robust_demo(
2654
request: FixtureRequest,

tests/unit_tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Unit tests for cookiecutter-robust-python."""
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from functools import partial
2+
from typing import Any
3+
4+
import pytest
5+
6+
from util import templates_matching
7+
8+
9+
@pytest.mark.parametrize(
10+
argnames="robust_demo__add_rust_extension",
11+
argvalues=[False, True],
12+
indirect=True,
13+
ids=["base", "maturin"]
14+
)
15+
class TestWorkflow:
16+
@pytest.mark.parametrize(
17+
argnames="robust_file__path__relative",
18+
argvalues=templates_matching(".github/workflows/*.yml"),
19+
indirect=True,
20+
ids=lambda path: path.name
21+
)
22+
def test_workflow_basic_loading(self, robust_yaml: dict[str, Any]) -> None:
23+
assert robust_yaml

tests/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Module containing utility functions used by tests."""
2+
from pathlib import Path
3+
4+
from constants import COOKIECUTTER_FOLDER
5+
6+
7+
def templates_matching(pattern: str) -> list[Path]:
8+
"""Return a list of relative file paths matching the given pattern."""
9+
return list(COOKIECUTTER_FOLDER.glob(pattern))

0 commit comments

Comments
 (0)