3
3
import tempfile
4
4
from functools import partial
5
5
from io import StringIO
6
+ from tempfile import NamedTemporaryFile
6
7
7
8
import pytest
8
9
21
22
22
23
def test_pack ():
23
24
loadingContext , workflowobj , uri = fetch_document (get_data ("tests/wf/revsort.cwl" ))
24
- loadingContext .do_update = False
25
- loadingContext , uri = resolve_and_validate_document (
26
- loadingContext , workflowobj , uri
27
- )
28
- processobj = loadingContext .loader .resolve_ref (uri )[0 ]
29
25
30
26
with open (get_data ("tests/wf/expect_packed.cwl" )) as packed_file :
31
27
expect_packed = yaml .safe_load (packed_file )
32
28
33
- packed = cwltool .pack .pack (
34
- loadingContext .loader , processobj , uri , loadingContext .metadata
35
- )
29
+ packed = cwltool .pack .pack (loadingContext .loader , uri , loadingContext .metadata )
36
30
adjustFileObjs (
37
31
packed , partial (make_relative , os .path .abspath (get_data ("tests/wf" )))
38
32
)
@@ -59,9 +53,7 @@ def test_pack_input_named_name():
59
53
with open (get_data ("tests/wf/expect_trick_packed.cwl" )) as packed_file :
60
54
expect_packed = yaml .round_trip_load (packed_file )
61
55
62
- packed = cwltool .pack .pack (
63
- loadingContext .loader , processobj , uri , loadingContext .metadata
64
- )
56
+ packed = cwltool .pack .pack (loadingContext .loader , uri , loadingContext .metadata )
65
57
adjustFileObjs (
66
58
packed , partial (make_relative , os .path .abspath (get_data ("tests/wf" )))
67
59
)
@@ -85,10 +77,26 @@ def test_pack_single_tool():
85
77
)
86
78
processobj = loadingContext .loader .resolve_ref (uri )[0 ]
87
79
80
+ packed = cwltool .pack .pack (loadingContext .loader , uri , loadingContext .metadata )
81
+ assert "$schemas" in packed
82
+
83
+
84
+ def test_pack_fragment ():
85
+ with open (get_data ("tests/wf/scatter2_subwf.cwl" )) as packed_file :
86
+ expect_packed = yaml .safe_load (packed_file )
87
+
88
+ loadingContext , workflowobj , uri = fetch_document (get_data ("tests/wf/scatter2.cwl" ))
88
89
packed = cwltool .pack .pack (
89
- loadingContext .loader , processobj , uri , loadingContext .metadata
90
+ loadingContext .loader , uri + "#scatterstep/mysub" , loadingContext .metadata
91
+ )
92
+ adjustFileObjs (
93
+ packed , partial (make_relative , os .path .abspath (get_data ("tests/wf" )))
94
+ )
95
+ adjustDirObjs (packed , partial (make_relative , os .path .abspath (get_data ("tests/wf" ))))
96
+
97
+ assert json .dumps (packed , sort_keys = True , indent = 2 ) == json .dumps (
98
+ expect_packed , sort_keys = True , indent = 2
90
99
)
91
- assert "$schemas" in packed
92
100
93
101
94
102
def test_pack_rewrites ():
@@ -104,11 +112,7 @@ def test_pack_rewrites():
104
112
processobj = loadingContext .loader .resolve_ref (uri )[0 ]
105
113
106
114
cwltool .pack .pack (
107
- loadingContext .loader ,
108
- processobj ,
109
- uri ,
110
- loadingContext .metadata ,
111
- rewrite_out = rewrites ,
115
+ loadingContext .loader , uri , loadingContext .metadata , rewrite_out = rewrites ,
112
116
)
113
117
114
118
assert len (rewrites ) == 6
@@ -132,9 +136,7 @@ def test_pack_missing_cwlVersion(cwl_path):
132
136
processobj = loadingContext .loader .resolve_ref (uri )[0 ]
133
137
134
138
# generate pack output dict
135
- packed = json .loads (
136
- print_pack (loadingContext .loader , processobj , uri , loadingContext .metadata )
137
- )
139
+ packed = json .loads (print_pack (loadingContext .loader , uri , loadingContext .metadata ))
138
140
139
141
assert packed ["cwlVersion" ] == "v1.0"
140
142
@@ -158,19 +160,29 @@ def _pack_idempotently(document):
158
160
processobj = loadingContext .loader .resolve_ref (uri )[0 ]
159
161
160
162
# generate pack output dict
161
- packed = json .loads (
162
- print_pack (loadingContext .loader , processobj , uri , loadingContext .metadata )
163
- )
164
-
165
- loadingContext , workflowobj , uri2 = fetch_document (packed )
166
- loadingContext .do_update = False
167
- loadingContext , uri2 = resolve_and_validate_document (
168
- loadingContext , workflowobj , uri
169
- )
170
- processobj = loadingContext .loader .resolve_ref (uri2 )[0 ]
171
- double_packed = json .loads (
172
- print_pack (loadingContext .loader , processobj , uri2 , loadingContext .metadata )
173
- )
163
+ packed_text = print_pack (loadingContext .loader , uri , loadingContext .metadata )
164
+ packed = json .loads (packed_text )
165
+
166
+ tmp = NamedTemporaryFile (mode = "w" , delete = False )
167
+ try :
168
+ tmp .write (packed_text )
169
+ tmp .flush ()
170
+ tmp .close ()
171
+
172
+ loadingContext , workflowobj , uri2 = fetch_document (tmp .name )
173
+ loadingContext .do_update = False
174
+ loadingContext , uri2 = resolve_and_validate_document (
175
+ loadingContext , workflowobj , uri2
176
+ )
177
+ processobj = loadingContext .loader .resolve_ref (uri2 )[0 ]
178
+
179
+ # generate pack output dict
180
+ packed_text = print_pack (loadingContext .loader , uri2 , loadingContext .metadata )
181
+ double_packed = json .loads (packed_text )
182
+ finally :
183
+ os .remove (tmp .name )
184
+
185
+ assert uri != uri2
174
186
assert packed == double_packed
175
187
176
188
@@ -191,9 +203,7 @@ def test_packed_workflow_execution(wf_path, job_path, namespaced, tmpdir):
191
203
loadingContext , workflowobj , uri
192
204
)
193
205
processobj = loadingContext .loader .resolve_ref (uri )[0 ]
194
- packed = json .loads (
195
- print_pack (loadingContext .loader , processobj , uri , loadingContext .metadata )
196
- )
206
+ packed = json .loads (print_pack (loadingContext .loader , uri , loadingContext .metadata ))
197
207
198
208
assert not namespaced or "$namespaces" in packed
199
209
0 commit comments