Skip to content

Commit 481418d

Browse files
committed
feat: expand and refactor integration tests for the template
1 parent 2304db3 commit 481418d

File tree

2 files changed

+51
-32
lines changed

2 files changed

+51
-32
lines changed

tests/conftest.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""Fixtures used in all tests for cookiecutter-robust-python."""
22

3-
import os
43
import subprocess
54
from pathlib import Path
6-
from typing import Generator
75

86
import pytest
97
from _pytest.tmpdir import TempPathFactory
@@ -16,49 +14,37 @@
1614

1715

1816
@pytest.fixture(scope="session")
19-
def robust_python_demo_path(tmp_path_factory: TempPathFactory) -> Path:
17+
def demos_folder(tmp_path_factory: TempPathFactory) -> Path:
18+
"""Temp Folder used for storing demos while testing."""
19+
return tmp_path_factory.mktemp("demos")
20+
21+
22+
@pytest.fixture(scope="session")
23+
def robust_python_demo_path(demos_folder: Path) -> Path:
2024
"""Creates a temporary example python project for testing against and returns its Path."""
21-
demos_path: Path = tmp_path_factory.mktemp("demos")
2225
cookiecutter(
2326
str(REPO_FOLDER),
2427
no_input=True,
2528
overwrite_if_exists=True,
26-
output_dir=demos_path,
29+
output_dir=demos_folder,
2730
extra_context={"project_name": "robust-python-demo", "add_rust_extension": False},
2831
)
29-
path: Path = demos_path / "robust-python-demo"
30-
subprocess.run(["uv", "lock"], cwd=path)
32+
path: Path = demos_folder / "robust-python-demo"
33+
subprocess.run(["nox", "-s", "setup-repo"], cwd=path, capture_output=True)
3134
return path
3235

3336

3437
@pytest.fixture(scope="session")
35-
def robust_maturin_demo_path(tmp_path_factory: TempPathFactory) -> Path:
38+
def robust_maturin_demo_path(demos_folder: Path) -> Path:
3639
"""Creates a temporary example maturin project for testing against and returns its Path."""
37-
demos_path: Path = tmp_path_factory.mktemp("demos")
3840
cookiecutter(
3941
str(REPO_FOLDER),
4042
no_input=True,
4143
overwrite_if_exists=True,
42-
output_dir=demos_path,
43-
extra_context={"project_name": "robust-maturin-demo", "add_rust_extension": True},
44+
output_dir=demos_folder,
45+
extra_context={"project_name": "robust-maturin-demo", "add_rust_extension": True}
4446
)
45-
path: Path = demos_path / "robust-maturin-demo"
46-
subprocess.run(["uv", "sync"], cwd=path)
47+
path: Path = demos_folder / "robust-maturin-demo"
48+
subprocess.run(["nox", "-s", "setup-repo"], cwd=path, capture_output=True)
4749
return path
4850

49-
50-
@pytest.fixture(scope="function")
51-
def inside_robust_python_demo(robust_python_demo_path: Path) -> Generator[Path, None, None]:
52-
"""Changes the current working directory to the robust-python-demo project."""
53-
original_path: Path = Path.cwd()
54-
os.chdir(robust_python_demo_path)
55-
yield robust_python_demo_path
56-
os.chdir(original_path)
57-
58-
59-
@pytest.fixture(scope="function")
60-
def inside_robust_maturin_demo(robust_maturin_demo_path: Path) -> Generator[Path, None, None]:
61-
original_path: Path = Path.cwd()
62-
os.chdir(robust_maturin_demo_path)
63-
yield robust_maturin_demo_path
64-
os.chdir(original_path)

tests/integration_tests/test_robust_python_demo.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,48 @@ def test_demo_project_generation(robust_python_demo_path: Path) -> None:
1313

1414

1515
@pytest.mark.parametrize("session", GLOBAL_NOX_SESSIONS)
16-
def test_demo_project_noxfile(robust_python_demo_path: Path, session: str) -> None:
17-
command: list[str] = ["uvx", "nox", "-s", session]
16+
def test_demo_project_nox_session(robust_python_demo_path: Path, session: str) -> None:
17+
command: list[str] = ["nox", "-s", session]
1818
result: subprocess.CompletedProcess = subprocess.run(
1919
command,
2020
cwd=robust_python_demo_path,
2121
capture_output=True,
2222
text=True,
23-
timeout=10.0,
23+
timeout=20.0
2424
)
2525
print(result.stdout)
2626
print(result.stderr)
2727
result.check_returncode()
28+
29+
30+
def test_demo_project_nox_pre_commit(robust_python_demo_path: Path) -> None:
31+
command: list[str] = ["nox", "-s", "pre-commit"]
32+
result: subprocess.CompletedProcess = subprocess.run(
33+
command,
34+
cwd=robust_python_demo_path,
35+
capture_output=True,
36+
text=True,
37+
timeout=20.0
38+
)
39+
assert result.returncode == 0
40+
41+
42+
def test_demo_project_nox_pre_commit_with_install(robust_python_demo_path: Path) -> None:
43+
command: list[str] = ["nox", "-s", "pre-commit", "--", "install"]
44+
pre_commit_hook_path: Path = robust_python_demo_path / ".git" / "hooks" / "pre-commit"
45+
assert not pre_commit_hook_path.exists()
46+
47+
result: subprocess.CompletedProcess = subprocess.run(
48+
command,
49+
cwd=robust_python_demo_path,
50+
capture_output=True,
51+
text=True,
52+
timeout=20.0
53+
)
54+
assert pre_commit_hook_path.exists()
55+
assert pre_commit_hook_path.is_file()
56+
57+
assert result.returncode == 0
58+
59+
60+

0 commit comments

Comments
 (0)