Skip to content

Commit d4e142d

Browse files
committed
pack.py: add 'cwlVersion' in pack dict, if only single item exists
test_pack.py: add test for single item workflow test_pack.py: Use `single step` instead of `single item` in test function
1 parent 8d5b3e8 commit d4e142d

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

cwltool/pack.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,9 @@ def rewrite_id(r, mainuri):
157157

158158
import_embed(packed, set())
159159

160+
if len(packed["$graph"]) == 1:
161+
# duplicate 'cwlVersion' inside $graph when there is a single item
162+
# because we're printing contents inside '$graph' rather than whole dict
163+
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
164+
160165
return packed

tests/test_pack.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ def test_pack(self):
3333
del expect_packed["$schemas"]
3434

3535
self.assertEqual(expect_packed, packed)
36+
37+
def test_pack_single_step(self):
38+
"""Test to ensure the generated pack output is not missing
39+
the `cwlVersion` in case of single step workflow"""
40+
# Since diff is longer than 3174 characters
41+
self.maxDiff = None
42+
43+
document_loader, workflowobj, uri = fetch_document(
44+
get_data("tests/wf/hello-workflow.cwl"))
45+
document_loader, avsc_names, processobj, metadata, uri = validate_document(
46+
document_loader, workflowobj, uri)
47+
# generate pack output dict
48+
packed = cwltool.pack.pack(document_loader, processobj, uri, metadata)
49+
# open expect packed output
50+
with open(get_data("tests/wf/expect_packed_hello_workflow.cwl")) as f:
51+
expect_packed = json.load(f)
52+
print(json.dumps(expect_packed))
53+
adjustFileObjs(packed, partial(makeRelative,
54+
os.path.abspath(get_data("tests/wf"))))
55+
adjustDirObjs(packed, partial(makeRelative,
56+
os.path.abspath(get_data("tests/wf"))))
57+
58+
print(json.dumps(packed["$graph"][0]))
59+
self.assertEqual(expect_packed, packed["$graph"][0])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"class": "CommandLineTool",
3+
"baseCommand": "echo",
4+
"inputs": [
5+
{
6+
"type": "string",
7+
"inputBinding": {
8+
"position": 1
9+
},
10+
"id": "#main/message"
11+
}
12+
],
13+
"outputs": [],
14+
"id": "#main",
15+
"cwlVersion": "v1.0"
16+
}

tests/wf/hello-workflow.cwl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand: echo
4+
inputs:
5+
message:
6+
type: string
7+
inputBinding:
8+
position: 1
9+
outputs: []

0 commit comments

Comments
 (0)