1313
1414
1515@pytest .mark .integration
16- @pytest .mark .parametrize ("repo_type" , [t . value for t in config .RepositoryType ])
17- def test_generation (tmp_path : pathlib .Path , repo_type : str ) -> None :
16+ @pytest .mark .parametrize ("repo_type" , [* config .RepositoryType ])
17+ def test_generation (tmp_path : pathlib .Path , repo_type : config . RepositoryType ) -> None :
1818 """Test generation of a new repo."""
1919 cwd = pathlib .Path ().cwd ()
20- _run (
20+ repo_path , _ = _generate_repo (repo_type , tmp_path )
21+ _run (repo_path , "python3" , "-m" , "venv" , ".venv" )
22+
23+ _update_pyproject_repo_config_dep (
24+ repo_config_path = cwd , repo_type = repo_type , repo_path = repo_path
25+ )
26+
27+ cmd = ". .venv/bin/activate; pip install .[dev-noxfile]; nox -e ci_checks_max pytest_min"
28+ print ()
29+ print (f"Running in shell [{ repo_path } ]: { cmd } " )
30+ subprocess .run (cmd , shell = True , cwd = repo_path , check = True )
31+
32+
33+ def _generate_repo (
34+ repo_type : config .RepositoryType ,
35+ tmp_path : pathlib .Path ,
36+ / ,
37+ * ,
38+ capture_output : bool = False ,
39+ ) -> tuple [pathlib .Path , subprocess .CompletedProcess [bytes ]]:
40+ cwd = pathlib .Path ().cwd ()
41+ run_result = _run (
2142 tmp_path ,
2243 "cookiecutter" ,
2344 "--no-input" ,
2445 str (cwd / "cookiecutter" ),
25- f"type={ repo_type } " ,
46+ f"type={ repo_type . value } " ,
2647 "name=test" ,
2748 "description=Test description" ,
49+ capture_output = capture_output ,
2850 )
2951
3052 subdirs = list (tmp_path .iterdir ())
3153 assert len (subdirs ) == 1
3254 repo_path = subdirs [0 ]
33- _run (repo_path , "python3" , "-m" , "venv" , ".venv" )
34-
35- _update_pyproject_repo_config_dep (
36- repo_config_path = cwd , repo_type = repo_type , repo_path = repo_path
37- )
38-
39- cmd = ". .venv/bin/activate; pip install .[dev-noxfile]; nox -e ci_checks_max pytest_min"
40- print ()
41- print (f"Running in shell [{ repo_path } ]: { cmd } " )
42- subprocess .run (cmd , shell = True , cwd = repo_path , check = True )
55+ return repo_path , run_result
4356
4457
45- def _run (cwd : pathlib .Path , * cmd : str ) -> subprocess .CompletedProcess [bytes ]:
58+ def _run (
59+ cwd : pathlib .Path , / , * cmd : str , capture_output : bool = False , check : bool = True
60+ ) -> subprocess .CompletedProcess [bytes ]:
61+ """Run a command in a subprocess."""
4662 print ()
4763 print ("-" * 80 )
4864 print (f"Running [{ cwd } ]: { ' ' .join (cmd )} " )
4965 print ()
50- return subprocess .run (cmd , cwd = cwd , check = True )
66+ return subprocess .run (cmd , cwd = cwd , check = check , capture_output = capture_output )
5167
5268
5369def _update_pyproject_repo_config_dep (
54- * , repo_config_path : pathlib .Path , repo_type : str , repo_path : pathlib .Path
70+ * ,
71+ repo_config_path : pathlib .Path ,
72+ repo_type : config .RepositoryType ,
73+ repo_path : pathlib .Path ,
5574) -> None :
5675 """Update the repo config dependency in the generated pyproject.toml.
5776
@@ -64,8 +83,12 @@ def _update_pyproject_repo_config_dep(
6483 repo_type: Type of the repo to generate.
6584 repo_path: Path to the generated repo.
6685 """
67- repo_config_dep = f"frequenz-repo-config[{ repo_type } ] @ file://{ repo_config_path } "
68- repo_config_dep_re = re .compile (rf"""frequenz-repo-config\[{ repo_type } \][^"]+""" )
86+ repo_config_dep = (
87+ f"frequenz-repo-config[{ repo_type .value } ] @ file://{ repo_config_path } "
88+ )
89+ repo_config_dep_re = re .compile (
90+ rf"""frequenz-repo-config\[{ repo_type .value } \][^"]+"""
91+ )
6992
7093 with open (repo_path / "pyproject.toml" , encoding = "utf8" ) as pyproject_file :
7194 pyproject_content = pyproject_file .read ()
0 commit comments