Skip to content

Commit 7f4bc55

Browse files
committed
always include $namespaces in the #main
and improve the tests
1 parent 519331d commit 7f4bc55

File tree

6 files changed

+78
-61
lines changed

6 files changed

+78
-61
lines changed

cwltool/pack.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,15 @@ def rewrite_id(r, mainuri):
208208
import_embed(packed, set())
209209

210210
if len(packed["$graph"]) == 1:
211-
# duplicate 'cwlVersion' inside $graph when there is a single item
212-
# because we're printing contents inside '$graph' rather than whole dict
211+
# duplicate 'cwlVersion' and $schemas inside $graph when there is only
212+
# a single item because we will print the contents inside '$graph'
213+
# rather than whole dict
213214
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]
214-
if namespaces:
215-
packed["$graph"][0]["$namespaces"] = dict(cast(Dict, namespaces))
216215
if schemas:
217216
packed["$graph"][0]["$schemas"] = list(schemas)
217+
# always include $namespaces in the #main
218+
if namespaces:
219+
packed["$graph"][0]["$namespaces"] = dict(cast(Dict, namespaces))
218220

219221

220222
return packed

tests/test_pack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_pack():
3232
adjustDirObjs(packed, partial(make_relative, os.path.abspath(get_data("tests/wf"))))
3333

3434
assert "$schemas" in packed
35-
35+
assert len(packed["$schemas"]) == len(expect_packed["$schemas"])
3636
del packed["$schemas"]
3737
del expect_packed["$schemas"]
3838

tests/wf/empty2.ttl

Whitespace-only changes.

tests/wf/expect_packed.cwl

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
11
{
2-
"cwlVersion": "v1.0",
3-
"$schemas": ["file:///home/peter/work/cwltool/tests/wf/empty.ttl"],
42
"$graph": [
53
{
4+
"class": "Workflow",
5+
"doc": "Reverse the lines in a document, then sort those lines.",
6+
"hints": [
7+
{
8+
"class": "DockerRequirement",
9+
"dockerPull": "debian:8"
10+
}
11+
],
612
"inputs": [
713
{
8-
"doc": "The input file to be processed.",
914
"type": "File",
10-
"id": "#main/input",
15+
"doc": "The input file to be processed.",
16+
"format": "https://www.iana.org/assignments/media-types/text/plain",
1117
"default": {
12-
"class": "File",
13-
"location": "hello.txt"
14-
}
18+
"class": "File",
19+
"location": "hello.txt"
20+
},
21+
"id": "#main/input"
1522
},
1623
{
24+
"type": "boolean",
1725
"default": true,
1826
"doc": "If true, reverse (decending) sort",
19-
"type": "boolean",
2027
"id": "#main/reverse_sort"
2128
}
2229
],
23-
"doc": "Reverse the lines in a document, then sort those lines.",
24-
"class": "Workflow",
30+
"outputs": [
31+
{
32+
"type": "File",
33+
"outputSource": "#main/sorted/output",
34+
"doc": "The output with the lines reversed and sorted.",
35+
"id": "#main/output"
36+
}
37+
],
2538
"steps": [
2639
{
27-
"out": [
28-
"#main/rev/output"
29-
],
30-
"run": "#revtool.cwl",
31-
"id": "#main/rev",
3240
"in": [
3341
{
3442
"source": "#main/input",
3543
"id": "#main/rev/input"
3644
}
37-
]
38-
},
39-
{
45+
],
4046
"out": [
41-
"#main/sorted/output"
47+
"#main/rev/output"
4248
],
43-
"run": "#sorttool.cwl",
44-
"id": "#main/sorted",
49+
"run": "#revtool.cwl",
50+
"id": "#main/rev"
51+
},
52+
{
4553
"in": [
4654
{
4755
"source": "#main/rev/output",
@@ -51,80 +59,79 @@
5159
"source": "#main/reverse_sort",
5260
"id": "#main/sorted/reverse"
5361
}
54-
]
55-
}
56-
],
57-
"outputs": [
58-
{
59-
"outputSource": "#main/sorted/output",
60-
"type": "File",
61-
"id": "#main/output",
62-
"doc": "The output with the lines reversed and sorted."
62+
],
63+
"out": [
64+
"#main/sorted/output"
65+
],
66+
"run": "#sorttool.cwl",
67+
"id": "#main/sorted"
6368
}
6469
],
6570
"id": "#main",
66-
"hints": [
67-
{
68-
"dockerPull": "debian:8",
69-
"class": "DockerRequirement"
70-
}
71-
]
71+
"$namespaces": {
72+
"iana": "https://www.iana.org/assignments/media-types/"
73+
}
7274
},
7375
{
76+
"class": "CommandLineTool",
77+
"doc": "Reverse each line using the `rev` command",
7478
"inputs": [
7579
{
76-
"inputBinding": {},
7780
"type": "File",
81+
"inputBinding": {},
7882
"id": "#revtool.cwl/input"
7983
}
8084
],
81-
"stdout": "output.txt",
82-
"doc": "Reverse each line using the `rev` command",
83-
"baseCommand": "rev",
84-
"class": "CommandLineTool",
8585
"outputs": [
8686
{
87+
"type": "File",
8788
"outputBinding": {
8889
"glob": "output.txt"
8990
},
90-
"type": "File",
9191
"id": "#revtool.cwl/output"
9292
}
9393
],
94+
"baseCommand": "rev",
95+
"stdout": "output.txt",
9496
"id": "#revtool.cwl"
9597
},
9698
{
99+
"class": "CommandLineTool",
100+
"doc": "Sort lines using the `sort` command",
97101
"inputs": [
98102
{
103+
"id": "#sorttool.cwl/reverse",
104+
"type": "boolean",
99105
"inputBinding": {
100106
"position": 1,
101107
"prefix": "--reverse"
102-
},
103-
"type": "boolean",
104-
"id": "#sorttool.cwl/reverse"
108+
}
105109
},
106110
{
111+
"id": "#sorttool.cwl/input",
112+
"type": "File",
107113
"inputBinding": {
108114
"position": 2
109-
},
110-
"type": "File",
111-
"id": "#sorttool.cwl/input"
115+
}
112116
}
113117
],
114-
"stdout": "output.txt",
115-
"doc": "Sort lines using the `sort` command",
116-
"baseCommand": "sort",
117-
"class": "CommandLineTool",
118118
"outputs": [
119119
{
120+
"id": "#sorttool.cwl/output",
121+
"type": "File",
120122
"outputBinding": {
121123
"glob": "output.txt"
122-
},
123-
"type": "File",
124-
"id": "#sorttool.cwl/output"
124+
}
125125
}
126126
],
127+
"baseCommand": "sort",
128+
"stdout": "output.txt",
127129
"id": "#sorttool.cwl"
128130
}
131+
],
132+
"cwlVersion": "v1.0",
133+
"$schemas": [
134+
"file:///home/mcrusoe/cwltool/tests/wf/empty2.ttl",
135+
"file:///home/mcrusoe/cwltool/tests/wf/empty.ttl"
129136
]
130137
}

tests/wf/revsort-job.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"input": {
33
"class": "File",
4-
"location": "whale.txt"
4+
"location": "whale.txt",
5+
"format": "https://www.iana.org/assignments/media-types/text/plain"
56
}
67
}

tests/wf/revsort.cwl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ inputs:
2424
input:
2525
type: File
2626
doc: "The input file to be processed."
27+
format: iana:text/plain
2728
default:
2829
class: File
2930
location: hello.txt
@@ -67,3 +68,9 @@ steps:
6768
reverse: reverse_sort
6869
out: [output]
6970
run: sorttool.cwl
71+
72+
$namespaces:
73+
iana: https://www.iana.org/assignments/media-types/
74+
75+
$schemas:
76+
- empty2.ttl

0 commit comments

Comments
 (0)