1+ from __future__ import annotations
2+
13import os
24import shlex
35import subprocess
4- from contextlib import contextmanager
5-
6-
7- @contextmanager
8- def run_within_dir (path : str ):
9- oldpwd = os .getcwd ()
10- os .chdir (path )
11- try :
12- yield
13- finally :
14- os .chdir (oldpwd )
15-
166
17- def file_contains_text (file : str , text : str ) -> bool :
18- with open (file ) as f :
19- return f .read ().find (text ) != - 1
7+ from tests .utils import file_contains_text , is_valid_yaml , run_within_dir
208
219
2210def test_bake_project (cookies ):
@@ -37,6 +25,7 @@ def test_using_pytest(cookies, tmp_path):
3725 assert result .exception is None
3826 assert result .project_path .name == "example-project"
3927 assert result .project_path .is_dir ()
28+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
4029
4130 # Install the poetry environment and run the tests.
4231 with run_within_dir (str (result .project_path )):
@@ -66,6 +55,7 @@ def test_cicd_contains_artifactory_secrets(cookies, tmp_path):
6655 with run_within_dir (tmp_path ):
6756 result = cookies .bake (extra_context = {"publish_to" : "artifactory" })
6857 assert result .exit_code == 0
58+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
6959 for text in ["ARTIFACTORY_URL" , "ARTIFACTORY_USERNAME" , "ARTIFACTORY_PASSWORD" ]:
7060 assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , text )
7161 assert file_contains_text (f"{ result .project_path } /Makefile" , "build-and-publish" )
@@ -75,6 +65,7 @@ def test_cicd_contains_pypi_secrets(cookies, tmp_path):
7565 with run_within_dir (tmp_path ):
7666 result = cookies .bake (extra_context = {"publish_to" : "pypi" })
7767 assert result .exit_code == 0
68+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
7869 assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , "PYPI_TOKEN" )
7970 assert file_contains_text (f"{ result .project_path } /Makefile" , "build-and-publish" )
8071
@@ -83,6 +74,7 @@ def test_dont_publish(cookies, tmp_path):
8374 with run_within_dir (tmp_path ):
8475 result = cookies .bake (extra_context = {"publish_to" : "none" })
8576 assert result .exit_code == 0
77+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
8678 assert not file_contains_text (
8779 f"{ result .project_path } /.github/workflows/on-release-main.yml" , "make build-and-publish"
8880 )
@@ -92,6 +84,8 @@ def test_mkdocs(cookies, tmp_path):
9284 with run_within_dir (tmp_path ):
9385 result = cookies .bake (extra_context = {"mkdocs" : "y" })
9486 assert result .exit_code == 0
87+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
88+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
9589 assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , "mkdocs gh-deploy" )
9690 assert file_contains_text (f"{ result .project_path } /Makefile" , "docs:" )
9791 assert os .path .isdir (f"{ result .project_path } /docs" )
@@ -101,6 +95,8 @@ def test_not_mkdocs(cookies, tmp_path):
10195 with run_within_dir (tmp_path ):
10296 result = cookies .bake (extra_context = {"mkdocs" : "n" })
10397 assert result .exit_code == 0
98+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
99+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
104100 assert not file_contains_text (
105101 f"{ result .project_path } /.github/workflows/on-release-main.yml" , "mkdocs gh-deploy"
106102 )
@@ -112,7 +108,6 @@ def test_tox(cookies, tmp_path):
112108 with run_within_dir (tmp_path ):
113109 result = cookies .bake ()
114110 assert result .exit_code == 0
115- assert file_contains_text (f"{ result .project_path } /.github/workflows/main.yml" , "pip install tox tox-gh-actions" )
116111 assert os .path .isfile (f"{ result .project_path } /tox.ini" )
117112 assert file_contains_text (f"{ result .project_path } /tox.ini" , "[tox]" )
118113
@@ -135,6 +130,7 @@ def test_codecov(cookies, tmp_path):
135130 with run_within_dir (tmp_path ):
136131 result = cookies .bake ()
137132 assert result .exit_code == 0
133+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
138134 assert os .path .isfile (f"{ result .project_path } /codecov.yaml" )
139135 assert os .path .isfile (f"{ result .project_path } /.github/workflows/validate-codecov-config.yml" )
140136
@@ -143,6 +139,7 @@ def test_not_codecov(cookies, tmp_path):
143139 with run_within_dir (tmp_path ):
144140 result = cookies .bake (extra_context = {"codecov" : "n" })
145141 assert result .exit_code == 0
142+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
146143 assert not os .path .isfile (f"{ result .project_path } /codecov.yaml" )
147144 assert not os .path .isfile (f"{ result .project_path } /.github/workflows/validate-codecov-config.yml" )
148145
0 commit comments