1
+ from __future__ import annotations
2
+
1
3
import os
2
4
import shlex
3
5
import 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
-
16
6
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
20
8
21
9
22
10
def test_bake_project (cookies ):
@@ -37,6 +25,7 @@ def test_using_pytest(cookies, tmp_path):
37
25
assert result .exception is None
38
26
assert result .project_path .name == "example-project"
39
27
assert result .project_path .is_dir ()
28
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
40
29
41
30
# Install the poetry environment and run the tests.
42
31
with run_within_dir (str (result .project_path )):
@@ -66,6 +55,7 @@ def test_cicd_contains_artifactory_secrets(cookies, tmp_path):
66
55
with run_within_dir (tmp_path ):
67
56
result = cookies .bake (extra_context = {"publish_to" : "artifactory" })
68
57
assert result .exit_code == 0
58
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
69
59
for text in ["ARTIFACTORY_URL" , "ARTIFACTORY_USERNAME" , "ARTIFACTORY_PASSWORD" ]:
70
60
assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , text )
71
61
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):
75
65
with run_within_dir (tmp_path ):
76
66
result = cookies .bake (extra_context = {"publish_to" : "pypi" })
77
67
assert result .exit_code == 0
68
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
78
69
assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , "PYPI_TOKEN" )
79
70
assert file_contains_text (f"{ result .project_path } /Makefile" , "build-and-publish" )
80
71
@@ -83,6 +74,7 @@ def test_dont_publish(cookies, tmp_path):
83
74
with run_within_dir (tmp_path ):
84
75
result = cookies .bake (extra_context = {"publish_to" : "none" })
85
76
assert result .exit_code == 0
77
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "on-release-main.yml" )
86
78
assert not file_contains_text (
87
79
f"{ result .project_path } /.github/workflows/on-release-main.yml" , "make build-and-publish"
88
80
)
@@ -92,6 +84,8 @@ def test_mkdocs(cookies, tmp_path):
92
84
with run_within_dir (tmp_path ):
93
85
result = cookies .bake (extra_context = {"mkdocs" : "y" })
94
86
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" )
95
89
assert file_contains_text (f"{ result .project_path } /.github/workflows/on-release-main.yml" , "mkdocs gh-deploy" )
96
90
assert file_contains_text (f"{ result .project_path } /Makefile" , "docs:" )
97
91
assert os .path .isdir (f"{ result .project_path } /docs" )
@@ -101,6 +95,8 @@ def test_not_mkdocs(cookies, tmp_path):
101
95
with run_within_dir (tmp_path ):
102
96
result = cookies .bake (extra_context = {"mkdocs" : "n" })
103
97
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" )
104
100
assert not file_contains_text (
105
101
f"{ result .project_path } /.github/workflows/on-release-main.yml" , "mkdocs gh-deploy"
106
102
)
@@ -112,7 +108,6 @@ def test_tox(cookies, tmp_path):
112
108
with run_within_dir (tmp_path ):
113
109
result = cookies .bake ()
114
110
assert result .exit_code == 0
115
- assert file_contains_text (f"{ result .project_path } /.github/workflows/main.yml" , "pip install tox tox-gh-actions" )
116
111
assert os .path .isfile (f"{ result .project_path } /tox.ini" )
117
112
assert file_contains_text (f"{ result .project_path } /tox.ini" , "[tox]" )
118
113
@@ -135,6 +130,7 @@ def test_codecov(cookies, tmp_path):
135
130
with run_within_dir (tmp_path ):
136
131
result = cookies .bake ()
137
132
assert result .exit_code == 0
133
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
138
134
assert os .path .isfile (f"{ result .project_path } /codecov.yaml" )
139
135
assert os .path .isfile (f"{ result .project_path } /.github/workflows/validate-codecov-config.yml" )
140
136
@@ -143,6 +139,7 @@ def test_not_codecov(cookies, tmp_path):
143
139
with run_within_dir (tmp_path ):
144
140
result = cookies .bake (extra_context = {"codecov" : "n" })
145
141
assert result .exit_code == 0
142
+ assert is_valid_yaml (result .project_path / ".github" / "workflows" / "main.yml" )
146
143
assert not os .path .isfile (f"{ result .project_path } /codecov.yaml" )
147
144
assert not os .path .isfile (f"{ result .project_path } /.github/workflows/validate-codecov-config.yml" )
148
145
0 commit comments