10
10
import os
11
11
import filecmp
12
12
import unittest
13
+ from tempfile import NamedTemporaryFile
13
14
14
15
# External libraries
15
16
import cwlgen
16
17
17
18
# Class(es) ------------------------------
18
19
19
- class TestCommandLineTool (unittest .TestCase ):
20
20
21
+ class TestWorkflow (unittest .TestCase ):
21
22
22
- def test_build (self ):
23
+ def capture_tempfile (self , func ):
24
+ with NamedTemporaryFile () as f :
25
+ func (f .name )
26
+ return f .read ()
27
+
28
+ def test_generates_workflow_two_steps (self ):
23
29
24
30
w = cwlgen .Workflow ()
25
31
tool = cwlgen .parse_cwl ("test/import_cwl.cwl" )
@@ -29,4 +35,56 @@ def test_build(self):
29
35
o1 = w .add ('step-a' , tool , {"INPUT1" : f })
30
36
o2 = w .add ('step-b' , tool , {"INPUT1" : o1 ['OUTPUT1' ]})
31
37
o2 ['OUTPUT1' ].store ()
32
- w .export ("test.cwl" )
38
+ generated = self .capture_tempfile (w .export )
39
+ expected = b"""#!/usr/bin/env cwl-runner
40
+
41
+ class: Workflow
42
+ cwlVersion: v1.0
43
+ inputs:
44
+ INPUT1: {id: INPUT1, type: File}
45
+ outputs:
46
+ step-b_OUTPUT1: {id: step-b_OUTPUT1, outputSource: step-b/OUTPUT1, type: File}
47
+ steps:
48
+ step-a:
49
+ id: step-a
50
+ in: {INPUT1: INPUT1}
51
+ out: [OUTPUT1]
52
+ run: test/import_cwl.cwl
53
+ step-b:
54
+ id: step-b
55
+ in: {INPUT1: step-a/OUTPUT1}
56
+ out: [OUTPUT1]
57
+ run: test/import_cwl.cwl
58
+ """
59
+ self .assertEqual (expected , generated )
60
+
61
+ def test_generates_workflow_int_inputs (self ):
62
+
63
+ w = cwlgen .Workflow ()
64
+ tool = cwlgen .parse_cwl ("test/int_tool.cwl" )
65
+
66
+ i = cwlgen .workflow .InputParameter ('INTEGER' , param_type = 'int' )
67
+ o1 = w .add ('step' , tool , {"INTEGER" : i })
68
+ o1 ['OUTPUT1' ].store ()
69
+
70
+ expected = b"""#!/usr/bin/env cwl-runner
71
+
72
+ class: Workflow
73
+ cwlVersion: v1.0
74
+ inputs:
75
+ INTEGER: {id: INTEGER, type: int}
76
+ outputs:
77
+ step_OUTPUT1: {id: step_OUTPUT1, outputSource: step/OUTPUT1, type: File}
78
+ steps:
79
+ step:
80
+ id: step
81
+ in: {INTEGER: INTEGER}
82
+ out: [OUTPUT1]
83
+ run: test/int_tool.cwl
84
+ """
85
+ generated = self .capture_tempfile (w .export )
86
+ self .assertEqual (expected , generated )
87
+
88
+
89
+
90
+
0 commit comments