-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_options.py
233 lines (176 loc) · 6.47 KB
/
test_options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from pathlib import Path
from .util import assert_file_contains, check_project
def test_base():
check_project(run_pytest=True)
def test_pip():
check_project(
settings={'package_manager': 'pip'},
files_existent=['requirements.txt', 'requirements-dev.txt', 'setup.py'],
files_non_existent=['environment.yml', 'environment-dev.yml'])
def test_conda():
check_project(
settings={'package_manager': 'conda'},
files_existent=['environment.yml', 'environment-dev.yml', 'setup.py'])
def test_poetry():
check_project(
settings={'package_manager': 'poetry'},
files_existent=['pyproject.toml'],
files_non_existent=['environment.yml, environment-dev.yml', 'requirements.txt', 'requirements-dev.txt', 'setup.py']
)
def test_notebooks_yes():
check_project(
settings={'use_notebooks': 'yes'},
files_existent=['notebooks'])
def test_notebooks_no():
check_project(
settings={'use_notebooks': 'no'},
files_non_existent=['notebooks'])
def test_docker_pip():
check_project(
settings={'use_docker': 'yes', 'package_manager': 'pip',},
files_existent=['Dockerfile', 'docker-compose.yml', '.dockerignore'])
def test_docker_conda():
check_project(
settings={'use_docker': 'yes', 'package_manager': 'conda',},
files_existent=['Dockerfile', 'docker-compose.yml', '.dockerignore'])
def test_docker_poetry():
check_project(
settings={'use_docker': 'yes', 'package_manager': 'poetry',},
files_existent=['Dockerfile', 'docker-compose.yml', '.dockerignore']
)
def test_docker_no():
check_project(
settings={'use_docker': 'no'},
files_non_existent=['Dockerfile', 'docker-compose.yml', '.dockerignore'])
def test_cli_yes():
check_project(
settings={'create_cli': 'yes'},
files_existent=['src/{module_name}/main.py', 'src/{module_name}/__main__.py'],
test_cli=True)
def test_cli_no():
check_project(
settings={'create_cli': 'no'},
files_non_existent=['src/{module_name}/__main__.py'],
test_cli=False)
def test_config_hocon():
check_project(
settings={'config_file': 'hocon', 'create_cli': 'yes'},
files_existent=['src/{module_name}/util.py', 'src/{module_name}/res/default.conf',
'config/dev.conf', 'config/prod.conf'],
files_non_existent=['config/config.yml'],
test_cli=True, run_pytest=True)
def test_config_yaml():
check_project(
settings={'config_file': 'yaml'},
files_existent=['src/{module_name}/util.py', 'config/config.yml'],
files_non_existent=['config/dev.conf', 'config/prod.conf', 'src/{module_name}/res/default.conf'],
run_pytest=True)
def test_config_none():
check_project(
settings={'config_file': 'none'},
files_non_existent=['config', 'src/{module_name}/util.py', 'tests/util.py',
'src/{module_name}/res'])
def test_formatter_black_pip():
def check_black(project_dir: Path):
assert_file_contains(project_dir / '.pre-commit-config.yaml', contains='psf/black')
assert_file_contains(project_dir / 'requirements-dev.txt', contains='black')
check_project(
settings={'code_formatter': 'black', 'package_manager': 'pip'},
fun=check_black)
def test_formatter_black_conda():
def check_black(project_dir: Path):
assert_file_contains(project_dir / '.pre-commit-config.yaml', contains='psf/black')
assert_file_contains(project_dir / 'environment-dev.yml', contains='black=')
check_project(
settings={'code_formatter': 'black', 'package_manager': 'conda'},
fun=check_black)
def test_formatter_black_poetry():
def check_black(project_dir: Path):
assert_file_contains(project_dir / '.pre-commit-config.yaml', contains='psf/black')
assert_file_contains(project_dir / 'pyproject.toml', contains='black')
check_project(
settings={'code_formatter': 'black', 'package_manager': 'poetry'},
fun=check_black
)
def test_formatter_none():
def check_white(project_dir: Path):
assert_file_contains(project_dir / '.pre-commit-config.yaml', not_contains='psf/black')
assert_file_contains(project_dir / 'environment-dev.yml', not_contains='black=')
check_project(
settings={'code_formatter': 'none'},
fun=check_white)
def test_editor_pycharm():
check_project(
settings={'editor_settings': 'pycharm'},
files_existent=['.idea'],
files_non_existent=['.vscode'])
def test_editor_vscode():
check_project(
settings={'editor_settings': 'vscode'},
files_existent=['.vscode/settings.json'],
files_non_existent=['.idea'])
def test_editor_none():
check_project(
settings={'editor_settings': 'none'},
files_non_existent=['.idea', '.vscode'])
def test_random_combination():
check_project(
settings={
'package_manager': 'pip',
'use_notebooks': 'no',
'config_file': 'hocon',
'use_docker': 'yes',
'create_cli': 'yes',
'code_formatter': 'none',
'editor_settings': 'pycharm',
},
test_cli=True, run_pytest=True)
def test_poetry_regression():
"""
Regression test for the bug:
Template test failure after creating template with package_manager=poetry
"""
check_project(
settings={
"package_manager": "poetry",
"use_notebooks": "no",
"config_file": "none",
"use_docker": "no",
"create_cli": "no",
"code_formatter": "none",
"editor_settings": "none",
},
test_cli=False,
run_pytest=True,
)
def test_gitlab_pip():
check_project(
settings={
"package_manager": "pip",
"ci_pipeline": "gitlab"
},
files_existent=[".gitlab-ci.yml"]
)
def test_gitlab_conda():
check_project(
settings={
"package_manager": "conda",
"ci_pipeline": "gitlab"
},
files_existent=[".gitlab-ci.yml"]
)
def test_gitlab_poetry():
check_project(
settings={
"package_manager": "poetry",
"ci_pipeline": "gitlab"
},
files_existent=[".gitlab-ci.yml"]
)
def test_no_ci_pipeline():
check_project(
settings={
"ci_pipeline": "none"
},
files_non_existent=[".gitlab-ci.yml"]
)