-
Notifications
You must be signed in to change notification settings - Fork 967
/
test_workflows_from_yaml.py
337 lines (304 loc) · 9.6 KB
/
test_workflows_from_yaml.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
from __future__ import print_function
import json
import os
from base.populators import uses_test_history
from base.workflow_fixtures import (
WORKFLOW_RUNTIME_PARAMETER_SIMPLE,
)
from .test_workflows import BaseWorkflowsApiTestCase
WORKFLOWS_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
class WorkflowsFromYamlApiTestCase(BaseWorkflowsApiTestCase):
def setUp(self):
super(WorkflowsFromYamlApiTestCase, self).setUp()
def _upload_and_download(self, yaml_workflow):
workflow_id = self._upload_yaml_workflow(yaml_workflow)
workflow = self._get("workflows/%s/download" % workflow_id).json()
return workflow
def test_simple_upload(self):
workflow = self._upload_and_download("""
class: GalaxyWorkflow
steps:
- type: input
label: the_input
- tool_id: cat1
state:
input1:
$link: 0
- tool_id: cat1
state:
input1:
$link: 1#out_file1
- tool_id: random_lines1
label: random_line_label
state:
num_lines: 10
input:
$link: 2#out_file1
seed_source:
seed_source_selector: set_seed
seed: asdf
""")
tool_count = {'random_lines1': 0, 'cat1': 0}
input_found = False
for step in workflow['steps'].values():
step_type = step['type']
if step_type == "data_input":
assert step['label'] == 'the_input'
input_found = True
else:
tool_id = step['tool_id']
tool_count[tool_id] += 1
if tool_id == "random_lines1":
assert step['label'] == "random_line_label"
assert input_found
assert tool_count['random_lines1'] == 1
assert tool_count['cat1'] == 2
# FIXME: This test fails on some machines due to (we're guessing) yaml.safe_loading
# order being not guaranteed and inconsistent across platforms. The workflow
# yaml.safe_loader probably needs to enforce order using something like the
# approach described here:
# https://stackoverflow.com/questions/13297744/pyyaml-control-ordering-of-items-called-by-yaml.safe_load
# def test_multiple_input( self ):
# history_id = self.dataset_populator.new_history()
# self._run_jobs("""
# steps:
# - type: input
# label: input1
# - type: input
# label: input2
# - tool_id: cat_list
# state:
# input1:
# - $link: input1
# - $link: input2
# test_data:
# input1: "hello world"
# input2: "123"
# """, history_id=history_id)
# contents1 = self.dataset_populator.get_history_dataset_content(history_id)
# assert contents1 == "hello world\n123\n"
def test_simple_output_actions(self):
history_id = self.dataset_populator.new_history()
self._run_jobs("""
class: GalaxyWorkflow
steps:
- type: input
label: input1
- tool_id: cat1
label: first_cat
state:
input1:
$link: 0
outputs:
out_file1:
hide: true
rename: "the new value"
- tool_id: cat1
state:
input1:
$link: first_cat#out_file1
test_data:
input1: "hello world"
""", history_id=history_id)
details1 = self.dataset_populator.get_history_dataset_details(history_id, hid=2)
assert not details1["visible"]
assert details1["name"] == "the new value", details1
details2 = self.dataset_populator.get_history_dataset_details(history_id, hid=3)
assert details2["visible"]
def test_inputs_to_steps(self):
history_id = self.dataset_populator.new_history()
self._run_jobs("""
class: GalaxyWorkflow
inputs:
- id: input1
steps:
- tool_id: cat1
label: first_cat
connect:
input1: input1
queries_0|input2: input1
test_data:
input1: "hello world"
""", history_id=history_id)
contents1 = self.dataset_populator.get_history_dataset_content(history_id)
self.assertEquals(contents1.strip(), "hello world\nhello world")
def test_outputs(self):
workflow_id = self._upload_yaml_workflow("""
class: GalaxyWorkflow
inputs:
- id: input1
outputs:
- id: wf_output_1
source: first_cat#out_file1
steps:
- tool_id: cat1
label: first_cat
state:
input1:
$link: input1
queries:
- input2:
$link: input1
test_data:
input1: "hello world"
""")
workflow = self._get("workflows/%s/download" % workflow_id).json()
self.assertEquals(workflow["steps"]["1"]["workflow_outputs"][0]["output_name"], "out_file1")
self.assertEquals(workflow["steps"]["1"]["workflow_outputs"][0]["label"], "wf_output_1")
def test_runtime_inputs(self):
workflow = self._upload_and_download(WORKFLOW_RUNTIME_PARAMETER_SIMPLE)
assert len(workflow["steps"]) == 2
runtime_step = workflow["steps"]["1"]
for runtime_input in runtime_step["inputs"]:
if runtime_input["name"] == "num_lines":
break
assert runtime_input["description"].startswith("runtime parameter for tool")
tool_state = json.loads(runtime_step["tool_state"])
assert "num_lines" in tool_state
self._assert_is_runtime_input(tool_state["num_lines"])
def test_subworkflow_simple(self):
workflow_id = self._upload_yaml_workflow("""
class: GalaxyWorkflow
inputs:
- id: outer_input
steps:
- tool_id: cat1
label: first_cat
state:
input1:
$link: outer_input
- run:
class: GalaxyWorkflow
inputs:
- id: inner_input
steps:
- tool_id: random_lines1
state:
num_lines: 1
input:
$link: inner_input
seed_source:
seed_source_selector: set_seed
seed: asdf
label: nested_workflow
connect:
inner_input: first_cat#out_file1
test_data:
outer_input:
value: 1.bed
type: File
""")
workflow = self._get("workflows/%s/download" % workflow_id).json()
by_label = self._steps_by_label(workflow)
if "nested_workflow" not in by_label:
template = "Workflow [%s] does not contain label 'nested_workflow'."
message = template % workflow
raise AssertionError(message)
subworkflow_step = by_label["nested_workflow"]
assert subworkflow_step["type"] == "subworkflow"
assert len(subworkflow_step["subworkflow"]["steps"]) == 2
subworkflow_connections = subworkflow_step["input_connections"]
assert len(subworkflow_connections) == 1
subworkflow_connection = subworkflow_connections["inner_input"]
assert subworkflow_connection["input_subworkflow_step_id"] == 0
workflow_reupload_id = self.import_workflow(workflow)["id"]
workflow_reupload = self._get("workflows/%s/download" % workflow_reupload_id).json()
by_label = self._steps_by_label(workflow_reupload)
subworkflow_step = by_label["nested_workflow"]
assert subworkflow_step["type"] == "subworkflow"
assert len(subworkflow_step["subworkflow"]["steps"]) == 2
subworkflow_connections = subworkflow_step["input_connections"]
assert len(subworkflow_connections) == 1
subworkflow_connection = subworkflow_connections["inner_input"]
assert subworkflow_connection["input_subworkflow_step_id"] == 0
# content = self.dataset_populator.get_history_dataset_content( history_id )
# self.assertEquals("chr5\t131424298\t131424460\tCCDS4149.1_cds_0_0_chr5_131424299_f\t0\t+\n", content)
def test_pause(self):
workflow_id = self._upload_yaml_workflow("""
class: GalaxyWorkflow
steps:
- label: test_input
type: input
- label: first_cat
tool_id: cat1
state:
input1:
$link: test_input
- label: the_pause
type: pause
in:
input: first_cat/out_file1
- label: second_cat
tool_id: cat1
in:
input1: the_pause
""")
print(self._get("workflows/%s/download" % workflow_id).json())
def test_implicit_connections(self):
workflow_id = self._upload_yaml_workflow("""
class: GalaxyWorkflow
steps:
- label: test_input
type: input
- label: first_cat
tool_id: cat1
state:
input1:
$link: test_input
- label: the_pause
type: pause
connect:
input:
- first_cat#out_file1
- label: second_cat
tool_id: cat1
state:
input1:
$link: the_pause
- label: third_cat
tool_id: cat1
connect:
$step: second_cat
state:
input1:
$link: test_input
""")
workflow = self._get("workflows/%s/download" % workflow_id).json()
print(workflow)
@uses_test_history()
def test_conditional_ints(self, history_id):
self._run_jobs("""
class: GalaxyWorkflow
steps:
- label: test_input
tool_id: disambiguate_cond
state:
p3:
use: true
files:
attach_files: false
""", test_data={}, history_id=history_id)
content = self.dataset_populator.get_history_dataset_content(history_id)
assert "no file specified" in content
assert "7 7 4" in content
self._run_jobs("""
class: GalaxyWorkflow
steps:
- label: test_input
tool_id: disambiguate_cond
state:
p3:
use: true
p3v: 5
files:
attach_files: false
""", test_data={}, history_id=history_id)
content = self.dataset_populator.get_history_dataset_content(history_id)
assert "no file specified" in content
assert "7 7 5" in content
def _steps_by_label(self, workflow_as_dict):
by_label = {}
assert "steps" in workflow_as_dict, workflow_as_dict
for step in workflow_as_dict["steps"].values():
by_label[step['label']] = step
return by_label