Skip to content

Commit c9ac6c3

Browse files
committed
more tests
1 parent f8705d5 commit c9ac6c3

File tree

9 files changed

+539
-26
lines changed

9 files changed

+539
-26
lines changed

cwl_utils/graph_split.py

+10-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from typing import (
2121
IO,
2222
Any,
23-
TextIO,
2423
Union,
2524
cast,
2625
)
@@ -146,7 +145,8 @@ def my_represent_none(
146145
if output_format == "json":
147146
json_dump(entry, output_file)
148147
elif output_format == "yaml":
149-
yaml_dump(entry, output_file, pretty)
148+
with output_file.open("w", encoding="utf-8") as output_handle:
149+
yaml_dump(entry, output_handle, pretty)
150150

151151

152152
def rewrite(
@@ -247,15 +247,16 @@ def rewrite_schemadef(
247247
rewrite_import(entry)
248248
elif "name" in entry and "/" in entry["name"]:
249249
entry_file, entry["name"] = entry["name"].lstrip("#").split("/")
250-
for field in entry["fields"]:
250+
for field in entry.get("fields", []):
251251
field["name"] = field["name"].split("/")[2]
252252
rewrite_types(field, entry_file, True)
253253
with (output_dir / entry_file).open("a", encoding="utf-8") as entry_handle:
254254
yaml_dump(entry, entry_handle, pretty)
255255
entry["$import"] = entry_file
256256
del entry["name"]
257257
del entry["type"]
258-
del entry["fields"]
258+
if "fields" in entry:
259+
del entry["fields"]
259260
seen_imports = set()
260261

261262
def seen_import(entry: MutableMapping[str, Any]) -> bool:
@@ -280,32 +281,18 @@ def json_dump(entry: Any, output_file: Path) -> None:
280281

281282
def yaml_dump(
282283
entry: Any,
283-
output_file_or_handle: Union[str, Path, TextIOWrapper, TextIO],
284+
output_handle: TextIOWrapper,
284285
pretty: bool,
285286
) -> None:
286287
"""Output object as YAML."""
288+
if pretty:
289+
output_handle.write(stringify_dict(entry))
290+
return
287291
yaml = YAML(typ="rt", pure=True)
288292
yaml.default_flow_style = False
289293
yaml.indent = 4
290294
yaml.block_seq_indent = 2
291-
292-
if isinstance(output_file_or_handle, (str, Path)):
293-
with open(output_file_or_handle, "w", encoding="utf-8") as result_handle:
294-
if pretty:
295-
result_handle.write(stringify_dict(entry))
296-
return
297-
yaml.dump(entry, result_handle)
298-
return
299-
elif isinstance(output_file_or_handle, (TextIOWrapper, TextIO)):
300-
if pretty:
301-
output_file_or_handle.write(stringify_dict(entry))
302-
return
303-
yaml.dump(entry, output_file_or_handle)
304-
return
305-
else:
306-
raise ValueError(
307-
f"output_file_or_handle must be a string or a file handle but got {type(output_file_or_handle)}"
308-
)
295+
yaml.dump(entry, output_handle)
309296

310297

311298
if __name__ == "__main__":

test-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ cwlformat
55
pytest-mock >= 1.10.0
66
jsonschema >= 4.21.1
77
udocker
8+
cwltool

testdata/lib.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ var foo = function(x) {
33
}
44

55
var bar = function(n, x) {
6-
return `{n} engineers walk into a {x}`
7-
}
6+
return n + " engineers walk into a " + x
7+
}

testdata/remote-cwl/wf1-packed.cwl

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
{
2+
"$graph": [
3+
{
4+
"class": "CommandLineTool",
5+
"inputs": [
6+
{
7+
"type": "string",
8+
"inputBinding": {
9+
"position": 1,
10+
"valueFrom": "A_$(inputs.in1)_B_${return inputs.in1}_C_$(inputs.in1)"
11+
},
12+
"id": "#tool1.cwl/in1"
13+
}
14+
],
15+
"baseCommand": "echo",
16+
"arguments": [
17+
{
18+
"valueFrom": "$(runtime)"
19+
}
20+
],
21+
"stdout": "out.txt",
22+
"requirements": [
23+
{
24+
"expressionLib": [
25+
"var foo = function(x) {\n return 2 * x\n}\n\nvar bar = function(n, x) {\n return `{n} engineers walk into a {x}`\n}"
26+
],
27+
"class": "InlineJavascriptRequirement"
28+
}
29+
],
30+
"id": "#tool1.cwl",
31+
"outputs": [
32+
{
33+
"type": "string",
34+
"outputBinding": {
35+
"glob": "out.txt",
36+
"loadContents": true,
37+
"outputEval": "$(self)_D_$(runtime)"
38+
},
39+
"id": "#tool1.cwl/out1"
40+
}
41+
]
42+
},
43+
{
44+
"class": "CommandLineTool",
45+
"inputs": [
46+
{
47+
"type": "#testtypes.yml/my_boolean_array",
48+
"inputBinding": {
49+
"position": 1,
50+
"valueFrom": "A_$(inputs.in1)_B_${return inputs.in1}_C_$(inputs.in1)"
51+
},
52+
"id": "#tool2.cwl/in1"
53+
}
54+
],
55+
"baseCommand": "echo",
56+
"arguments": [
57+
{
58+
"valueFrom": "$(runtime)"
59+
}
60+
],
61+
"outputs": [
62+
{
63+
"type": "string",
64+
"outputBinding": {
65+
"glob": "out.txt",
66+
"loadContents": true,
67+
"outputEval": "$(self)_D_$(runtime)"
68+
},
69+
"id": "#tool2.cwl/out1"
70+
}
71+
],
72+
"stdout": "out.txt",
73+
"requirements": [
74+
{
75+
"types": [
76+
{
77+
"name": "#testtypes.yml/my_boolean_array",
78+
"type": "array",
79+
"items": "boolean",
80+
"label": "A boolean array"
81+
},
82+
{
83+
"name": "#testtypes.yml/my_enum",
84+
"type": "enum",
85+
"symbols": [
86+
"#testtypes.yml/my_enum/a",
87+
"#testtypes.yml/my_enum/b",
88+
"#testtypes.yml/my_enum/c"
89+
],
90+
"label": "A required enum"
91+
}
92+
],
93+
"class": "SchemaDefRequirement"
94+
}
95+
],
96+
"id": "#tool2.cwl"
97+
},
98+
{
99+
"class": "Workflow",
100+
"inputs": [
101+
{
102+
"id": "#main/in1",
103+
"type": "#testtypes.yml/my_boolean_array"
104+
}
105+
],
106+
"steps": [
107+
{
108+
"run": "#tool2.cwl",
109+
"in": [
110+
{
111+
"source": "#main/in1",
112+
"id": "#main/s1/in1"
113+
}
114+
],
115+
"out": [
116+
"#main/s1/out1"
117+
],
118+
"id": "#main/s1"
119+
},
120+
{
121+
"run": "#tool1.cwl",
122+
"in": [
123+
{
124+
"source": "#main/s1/out1",
125+
"id": "#main/s2/in1"
126+
}
127+
],
128+
"out": [
129+
"#main/s2/out1"
130+
],
131+
"id": "#main/s2"
132+
}
133+
],
134+
"outputs": [
135+
{
136+
"id": "#main/out1",
137+
"type": "string",
138+
"outputSource": "#main/s2/out1"
139+
}
140+
],
141+
"requirements": [
142+
{
143+
"types": [
144+
{
145+
"$import": "#testtypes.yml/my_boolean_array"
146+
},
147+
{
148+
"$import": "#testtypes.yml/my_enum"
149+
}
150+
],
151+
"class": "SchemaDefRequirement"
152+
}
153+
],
154+
"id": "#main"
155+
}
156+
],
157+
"cwlVersion": "v1.2"
158+
}

testdata/workflows/clt1.cwl

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.0
5+
6+
requirements:
7+
InitialWorkDirRequirement:
8+
listing:
9+
- entryname: inputs.txt
10+
entry: |
11+
$(inputs.in1.file.path)
12+
$(inputs.in1.meta.species)
13+
SchemaDefRequirement:
14+
types:
15+
- $import: ../types/recursive.yml
16+
- $import: ../types/array.yml
17+
- $import: ../types/singletype.yml
18+
# - $import: ../types/singletype2.yml
19+
20+
inputs:
21+
in1: ../types/recursive.yml#file_with_sample_meta
22+
in2:
23+
type: ../types/array.yml#study_meta_too
24+
in3:
25+
type: ../types/singletype.yml#simple_record
26+
# in4:
27+
# type: ../types/singletype2.yml#simple_record2
28+
in4:
29+
type: [string, ../types/recursive.yml#sample_meta]
30+
in5:
31+
type: Any?
32+
33+
outputs:
34+
out1:
35+
type: File
36+
outputBinding:
37+
glob: '*.txt'
38+
out2:
39+
type: ../types/array.yml#study_meta_too
40+
outputBinding:
41+
outputEval: $(inputs.in2)
42+
out3: stdout
43+
44+
baseCommand: [echo]
45+
arguments: [hello world]

testdata/workflows/link-to-clt1.cwl

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
clt1.cwl

0 commit comments

Comments
 (0)