|
1 | 1 | """Fixtures used in all tests for cookiecutter-robust-python.""" |
2 | 2 |
|
3 | | -import os |
4 | 3 | import subprocess |
5 | 4 | from pathlib import Path |
6 | | -from typing import Generator |
7 | 5 |
|
8 | 6 | import pytest |
9 | 7 | from _pytest.tmpdir import TempPathFactory |
|
16 | 14 |
|
17 | 15 |
|
18 | 16 | @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: |
20 | 24 | """Creates a temporary example python project for testing against and returns its Path.""" |
21 | | - demos_path: Path = tmp_path_factory.mktemp("demos") |
22 | 25 | cookiecutter( |
23 | 26 | str(REPO_FOLDER), |
24 | 27 | no_input=True, |
25 | 28 | overwrite_if_exists=True, |
26 | | - output_dir=demos_path, |
| 29 | + output_dir=demos_folder, |
27 | 30 | extra_context={"project_name": "robust-python-demo", "add_rust_extension": False}, |
28 | 31 | ) |
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) |
31 | 34 | return path |
32 | 35 |
|
33 | 36 |
|
34 | 37 | @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: |
36 | 39 | """Creates a temporary example maturin project for testing against and returns its Path.""" |
37 | | - demos_path: Path = tmp_path_factory.mktemp("demos") |
38 | 40 | cookiecutter( |
39 | 41 | str(REPO_FOLDER), |
40 | 42 | no_input=True, |
41 | 43 | 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} |
44 | 46 | ) |
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) |
47 | 49 | return path |
48 | 50 |
|
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) |
0 commit comments