-
Notifications
You must be signed in to change notification settings - Fork 88
/
Copy pathtest_cmd_workflow_lint.py
287 lines (230 loc) · 12.6 KB
/
test_cmd_workflow_lint.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
"""Tests for the ``workflow_lint`` command."""
import glob
import os
from .test_utils import (
CliTestCase,
TEST_DATA_DIR,
)
class CmdWorkflowLintTestCase(CliTestCase):
def test_gxformat2_examples_as_repos(self):
repos = glob.glob(_wf_repo("from_format2") + "/*")
for repo in repos:
repo_basename = os.path.basename(repo)
try:
expected_exit_code = int(repo_basename[0])
except ValueError:
# not a repo, just skip.
continue
lint_cmd = ["workflow_lint", "--skip", "tests,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=expected_exit_code)
def test_fail_level(self):
# ensure missing tests normally cause it to fail...
repo = _wf_repo("from_format2/0_basic_format2")
lint_cmd = ["workflow_lint", repo]
self._check_exit_code(lint_cmd, exit_code=1)
# ... but not if fail_level is error
repo = _wf_repo("from_format2/0_basic_format2")
lint_cmd = ["workflow_lint", "--fail_level", "error", repo]
self._check_exit_code(lint_cmd, exit_code=0)
def test_workflow_test_linting(self):
repo = _wf_repo("basic_format2_ok")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_native_ok")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_input_misspelled")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_input_missing")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_output_misnamed")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_missing_input")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
def test_workflow_test_linting_control(self):
# if we skip the tests linting - the above failures should pass
repo = _wf_repo("basic_format2_input_misspelled")
lint_cmd = ["workflow_lint", "--skip", "tests,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_input_missing")
lint_cmd = ["workflow_lint", "--skip", "tests,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_output_misnamed")
lint_cmd = ["workflow_lint", "--skip", "tests,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_missing_input")
lint_cmd = ["workflow_lint", "--skip", "tests,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
def test_workflow_dockstore_linting(self):
repo = _wf_repo("basic_format2_dockstore")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_empty")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_dockstore_invalid_yaml")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_dockstore_wrong_descriptor")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_dockstore_wrong_test_file")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
repo = _wf_repo("basic_format2_dockstore_misspelled_primary_key")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=1)
def test_workflow_dockstore_linting_control(self):
# run same tests as above but make sure if we skip dockstore they
# all pass
repo = _wf_repo("basic_format2_dockstore")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_empty")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_invalid_yaml")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_wrong_descriptor")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_wrong_test_file")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_dockstore_misspelled_primary_key")
lint_cmd = ["workflow_lint", "--skip", "dockstore,best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
def test_lint_test_examples(self):
tags_wf = os.path.join(TEST_DATA_DIR, "wf10-tags-and-rules.gxwf.yml")
lint_cmd = ["workflow_lint", "--skip", "best_practices", tags_wf]
self._check_exit_code(lint_cmd, exit_code=0)
def test_best_practices_linting_gx(self):
workflow_path = "/".join((TEST_DATA_DIR, "wf14-unlinted-best-practices.yml"))
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
warnings = [
"Workflow is not annotated.",
"Workflow does not specify a creator.",
"Workflow does not specify a license.",
"Workflow step with ID None has no annotation.",
"Workflow step with ID None has no label.",
"Workflow missing test cases.",
"Workflow step with ID None specifies an untyped parameter as an input.",
"Workflow step with ID None specifies an untyped parameter in the post-job actions.",
]
for warning in warnings:
assert warning in result.output
def test_best_practices_linting_ga(self):
workflow_path = "/".join((TEST_DATA_DIR, "wf14-unlinted-best-practices.ga"))
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
warnings = [
"Workflow is not annotated.",
"Workflow does not specify a creator.",
"Workflow does not specify a license.",
"Workflow step with ID 0 has no annotation.",
"Workflow step with ID 0 has no label.",
"Workflow missing test cases.",
"Workflow step with ID 1 specifies an untyped parameter as an input.",
"Workflow step with ID 1 specifies an untyped parameter in the post-job actions.",
]
for warning in warnings:
assert warning in result.output
def test_author_identifier_best_practices_linting_ga(self):
workflow_path = "/".join((TEST_DATA_DIR, "wf19-unlinted-author-identifier-best-practices.ga"))
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
warnings = [
'Creator identifier "0000-0002-1825-0097" should be a fully qualified URI, for example "https://orcid.org/0000-0002-1825-0097".',
]
for warning in warnings:
assert warning in result.output
def test_assertion_linting(self):
workflow_path = "/".join((TEST_DATA_DIR, "wf15-test-assertions.yml"))
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert (
"Invalid assertion in tests: assert_has_text got an unexpected keyword argument 'non_existent_attribute'"
in result.output
)
def test_json_value_out(self):
workflow_path = "/".join((TEST_DATA_DIR, "json_value_out.yml"))
lint_cmd = ["workflow_lint", workflow_path, "--fail_level", "error"]
self._check_exit_code(lint_cmd, exit_code=0)
def test_tool_id_linting_wrong_version(self):
workflow_path = "/".join(
(TEST_DATA_DIR, "wf_repos", "autoupdate_tests", "workflow_with_unexisting_version_of_tool.ga")
)
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert (
"ERROR: The tool toolshed.g2.bx.psu.edu/repos/bgruening/text_processing/tp_head_tool/0.1.0 is not in the toolshed"
in result.output
)
def test_tool_id_linting_wrong_tool(self):
workflow_path = "/".join((TEST_DATA_DIR, "wf_repos", "autoupdate_tests", "workflow_with_unexisting_tool.ga"))
lint_cmd = ["workflow_lint", workflow_path]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert "ERROR: The ToolShed returned an error when searching" in result.output
def test_workflow_linting_asserts(self):
repo = _wf_repo("basic_format2_ok_collection")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_ok_list")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
self._check_exit_code(lint_cmd, exit_code=0)
repo = _wf_repo("basic_format2_wrong_assert_list")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert "ERROR: Invalid assertion in tests: assert_has_text missing a required argument: 'text'" in result.output
repo = _wf_repo("basic_format2_collection_wrong_assert_list")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert "ERROR: Invalid assertion in tests: assert_has_line missing a required argument: 'line'" in result.output
repo = _wf_repo("basic_format2_collection_wrong_assert")
lint_cmd = ["workflow_lint", "--skip", "best_practices", repo]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
assert "ERROR: Invalid assertion in tests: assert_has_line missing a required argument: 'line'" in result.output
def test_workflow_linting_iwc(self):
# Check the output of workflow_lint --iwc on a basic workflow with .dockstore
for repo in [
_wf_repo("basic_format2_dockstore"),
_wf_repo(os.path.join("basic_format2_dockstore", "basic_format2.gxwf.yml")),
]:
lint_cmd = ["workflow_lint", "--skip", "best_practices", "--iwc", repo]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
errors = [
"The file README.md is missing but required.",
"The file CHANGELOG.md is missing but required.",
".dockstore.yml workflow entry missing recommended key name",
"Workflow have no 'authors' in the .dockstore.yml.",
"has no release",
]
for error in errors:
assert error in result.output
# Check that skipping the good steps makes it work
lint_cmd = [
"workflow_lint",
"--iwc",
"--skip",
"best_practices,required_files,dockstore_best_practices,release",
repo,
]
self._check_exit_code(lint_cmd, exit_code=0)
# Check the output of workflow_lint --iwc on a good workflow but with an issue with the release
repo = _wf_repo("basic_wf_iwc_invalid_version")
lint_cmd = ["workflow_lint", "--iwc", repo]
result = self._runner.invoke(self._cli.planemo, lint_cmd)
errors = ["The release of workflow", " does not match the version in the CHANGELOG."]
for error in errors:
assert error in result.output
# Check that skipping the good steps makes it work
lint_cmd = ["workflow_lint", "--iwc", "--skip", "release", repo]
self._check_exit_code(lint_cmd, exit_code=0)
def _wf_repo(rel_path):
return os.path.join(TEST_DATA_DIR, "wf_repos", rel_path)