22
33import subprocess
44from pathlib import Path
5+ from typing import Any
56
67import pytest
8+ from _pytest .fixtures import FixtureRequest
79from _pytest .tmpdir import TempPathFactory
810from cookiecutter .main import cookiecutter
911
@@ -19,32 +21,75 @@ def demos_folder(tmp_path_factory: TempPathFactory) -> Path:
1921 return tmp_path_factory .mktemp ("demos" )
2022
2123
24+ @pytest .mark .parametrize (argnames = ["robust_demo__name" ], argvalues = ["robust-python-demo-no-setup" ], indirect = True )
25+ @pytest .mark .parametrize (argnames = ["robust_demo__add_rust_extension" ], argvalues = [False ], indirect = True )
2226@pytest .fixture (scope = "session" )
23- def robust_python_demo_path (demos_folder : Path ) -> Path :
24- """Creates a temporary example python project for testing against and returns its Path."""
25- cookiecutter (
26- str (REPO_FOLDER ),
27- no_input = True ,
28- overwrite_if_exists = True ,
29- output_dir = demos_folder ,
30- extra_context = {"project_name" : "robust-python-demo" , "add_rust_extension" : False },
31- )
32- path : Path = demos_folder / "robust-python-demo"
33- subprocess .run (["nox" , "-s" , "setup-git" ], cwd = path , capture_output = True )
34- subprocess .run (["nox" , "-s" , "setup-venv" ], cwd = path , capture_output = True )
35- return path
27+ def robust_python_demo_no_setup (request : FixtureRequest , robust_demo : Path ) -> Path :
28+ return getattr (request , "param" , robust_demo )
29+
30+
31+ @pytest .mark .parametrize (argnames = ["robust_demo__name" ], argvalues = ["robust-python-demo-with-setup" ], indirect = True )
32+ @pytest .mark .parametrize (argnames = ["robust_demo__add_rust_extension" ], argvalues = [False ], indirect = True )
33+ @pytest .fixture (scope = "session" )
34+ def robust_python_demo_with_setup (request : FixtureRequest , robust_demo : Path ) -> Path :
35+ subprocess .run (["nox" , "-s" , "setup-git" ], cwd = robust_demo , capture_output = True )
36+ subprocess .run (["nox" , "-s" , "setup-venv" ], cwd = robust_demo , capture_output = True )
37+ return getattr (request , "param" , robust_demo )
38+
39+
40+ @pytest .mark .parametrize (argnames = ["robust_demo__name" ], argvalues = ["robust-maturin-demo-no-setup" ], indirect = True )
41+ @pytest .mark .parametrize (argnames = ["robust_demo__add_rust_extension" ], argvalues = [True ], indirect = True )
42+ @pytest .fixture (scope = "session" )
43+ def robust_maturin_demo_no_setup (request : FixtureRequest , robust_demo : Path ) -> Path :
44+ return getattr (request , "param" , robust_demo )
45+
46+
47+ @pytest .mark .parametrize (argnames = ["robust_demo__name" ], argvalues = ["robust-maturin-demo-with-setup" ], indirect = True )
48+ @pytest .mark .parametrize (argnames = ["robust_demo__add_rust_extension" ], argvalues = [True ], indirect = True )
49+ @pytest .fixture (scope = "session" )
50+ def robust_maturin_demo_with_setup (request : FixtureRequest , robust_demo : Path ) -> Path :
51+ subprocess .run (["nox" , "-s" , "setup-git" ], cwd = robust_demo , capture_output = True )
52+ subprocess .run (["nox" , "-s" , "setup-venv" ], cwd = robust_demo , capture_output = True )
53+ return getattr (request , "param" , robust_demo )
3654
3755
3856@pytest .fixture (scope = "session" )
39- def robust_maturin_demo_path (demos_folder : Path ) -> Path :
40- """Creates a temporary example maturin project for testing against and returns its Path."""
57+ def robust_demo (
58+ robust_demo__path : Path ,
59+ robust_demo__extra_context : dict [str , Any ]
60+ ) -> Path :
4161 cookiecutter (
4262 str (REPO_FOLDER ),
4363 no_input = True ,
4464 overwrite_if_exists = True ,
45- output_dir = demos_folder ,
46- extra_context = { "project_name" : "robust-maturin-demo" , "add_rust_extension" : True }
65+ output_dir = robust_demo__path ,
66+ extra_context = robust_demo__extra_context ,
4767 )
48- path : Path = demos_folder / "robust-maturin-demo"
49- subprocess .run (["nox" , "-s" , "setup-repo" ], cwd = path , capture_output = True )
50- return path
68+ return robust_demo__path
69+
70+
71+ @pytest .fixture (scope = "session" )
72+ def robust_demo__path (request : FixtureRequest , demos_folder : Path , robust_demo__name : str ) -> Path :
73+ return getattr (request , "param" , demos_folder / robust_demo__name )
74+
75+
76+ @pytest .fixture (scope = "session" )
77+ def robust_demo__name (request : FixtureRequest ) -> str :
78+ return getattr (request , "param" , "robust-demo" )
79+
80+
81+ @pytest .fixture (scope = "session" )
82+ def robust_demo__extra_context (
83+ request : FixtureRequest ,
84+ robust_demo__name : str ,
85+ robust_demo__add_rust_extension : bool
86+ ) -> dict [str , Any ]:
87+ return getattr (request , "param" , {
88+ "project_name" : robust_demo__name ,
89+ "add_rust_extension" : robust_demo__add_rust_extension
90+ })
91+
92+
93+ @pytest .fixture (scope = "session" )
94+ def robust_demo__add_rust_extension (request : FixtureRequest ) -> bool :
95+ return getattr (request , "param" , False )
0 commit comments