Skip to content

Commit df84c39

Browse files
authored
Fix tests for upgrade_document (#85)
* Add test for NetworkAccess * Add test for requirements in array notation
1 parent e2a05df commit df84c39

10 files changed

+116
-24
lines changed

cwlupgrader/main.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -366,29 +366,29 @@ def _v1_0_to_v1_1(document: CommentedMap, outdir: str) -> CommentedMap:
366366
move_up_loadcontents(document)
367367
network_access = has_hint_or_req(document, "NetworkAccess")
368368
listing = has_hint_or_req(document, "LoadListingRequirement")
369-
hints = document.get("hints", {})
369+
reqs = document.get("requirements", {})
370370
# TODO: add comments to explain the extra hints
371-
if isinstance(hints, MutableSequence):
371+
if isinstance(reqs, MutableSequence):
372372
if not network_access:
373-
hints.append({"class": "NetworkAccess", "networkAccess": True})
373+
reqs.append({"class": "NetworkAccess", "networkAccess": True})
374374
if not listing:
375-
hints.append(
375+
reqs.append(
376376
cmap(
377377
{
378378
"class": "LoadListingRequirement",
379379
"loadListing": "deep_listing",
380380
}
381381
)
382382
)
383-
elif isinstance(hints, MutableMapping):
383+
elif isinstance(reqs, MutableMapping):
384384
if not network_access:
385-
hints["NetworkAccess"] = {"networkAccess": True}
385+
reqs["NetworkAccess"] = {"networkAccess": True}
386386
if not listing:
387-
hints["LoadListingRequirement"] = cmap(
387+
reqs["LoadListingRequirement"] = cmap(
388388
{"loadListing": "deep_listing"}
389389
)
390-
if "hints" not in document:
391-
document["hints"] = hints
390+
if "requirements" not in document:
391+
document["requirements"] = reqs
392392
elif document["class"] == "ExpressionTool":
393393
move_up_loadcontents(document)
394394
cleanup_v1_0_input_bindings(document)

testdata/v1.0/listing_deep1-arr.cwl

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env cwl-runner
2+
class: CommandLineTool
3+
cwlVersion: v1.0
4+
requirements:
5+
- class: InlineJavascriptRequirement
6+
inputs:
7+
d: Directory
8+
outputs:
9+
out:
10+
type: boolean
11+
outputBinding:
12+
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
13+
baseCommand: "true"

testdata/v1.0/networkaccess.cwl

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
inputs: []
4+
outputs: []
5+
baseCommand: python
6+
arguments:
7+
- "-c"
8+
- valueFrom: |
9+
import urllib.request
10+
assert(urllib.request.urlopen("http://commonwl.org").code == 200)

testdata/v1.1/conflict-wf.cwl

+10-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ $graph:
66
hints:
77
ResourceRequirement:
88
ramMin: 8
9-
NetworkAccess:
10-
networkAccess: true
11-
LoadListingRequirement:
12-
loadListing: deep_listing
139
inputs:
1410
text:
1511
type: string
@@ -24,16 +20,17 @@ $graph:
2420
baseCommand: echo
2521
stdout: out.txt
2622

23+
requirements:
24+
NetworkAccess:
25+
networkAccess: true
26+
LoadListingRequirement:
27+
loadListing: deep_listing
2728
- id: cat
2829
class: CommandLineTool
2930
hints:
3031
ResourceRequirement:
3132
ramMin: 8
3233

33-
NetworkAccess:
34-
networkAccess: true
35-
LoadListingRequirement:
36-
loadListing: deep_listing
3734
inputs:
3835
file1:
3936
type: File
@@ -53,6 +50,11 @@ $graph:
5350
baseCommand: cat
5451
stdout: out.txt
5552

53+
requirements:
54+
NetworkAccess:
55+
networkAccess: true
56+
LoadListingRequirement:
57+
loadListing: deep_listing
5658
- class: Workflow
5759
id: collision
5860

testdata/v1.1/listing_deep1-arr.cwl

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env cwl-runner
2+
class: CommandLineTool
3+
cwlVersion: v1.1
4+
requirements:
5+
- class: InlineJavascriptRequirement
6+
- class: NetworkAccess
7+
networkAccess: true
8+
- class: LoadListingRequirement
9+
loadListing: deep_listing
10+
inputs:
11+
d: Directory
12+
outputs:
13+
out:
14+
type: boolean
15+
outputBinding:
16+
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
17+
baseCommand: "true"

testdata/v1.1/listing_deep1.cwl

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ requirements:
55
LoadListingRequirement:
66
loadListing: deep_listing
77
InlineJavascriptRequirement: {}
8+
NetworkAccess:
9+
networkAccess: true
810
inputs:
911
d: Directory
1012
outputs:

testdata/v1.1/networkaccess.cwl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.1
3+
requirements:
4+
NetworkAccess:
5+
networkAccess: true
6+
LoadListingRequirement:
7+
loadListing: deep_listing
8+
inputs: []
9+
outputs: []
10+
baseCommand: python
11+
arguments:
12+
- "-c"
13+
- valueFrom: |
14+
import urllib.request
15+
assert(urllib.request.urlopen("http://commonwl.org").code == 200)

testdata/v1.2/listing_deep1.cwl

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ requirements:
55
LoadListingRequirement:
66
loadListing: deep_listing
77
InlineJavascriptRequirement: {}
8+
NetworkAccess:
9+
networkAccess: true
810
inputs:
911
d: Directory
1012
outputs:

testdata/v1.2/networkaccess.cwl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.2
3+
requirements:
4+
NetworkAccess:
5+
networkAccess: true
6+
LoadListingRequirement:
7+
loadListing: deep_listing
8+
inputs: []
9+
outputs: []
10+
baseCommand: python
11+
arguments:
12+
- "-c"
13+
- valueFrom: |
14+
import urllib.request
15+
assert(urllib.request.urlopen("http://commonwl.org").code == 200)

tests/test_complete.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,41 @@ def test_invalid_target(tmp_path: Path) -> None:
4141
assert result is None
4242

4343

44-
def test_v1_0_to_v1_1(tmp_path: Path) -> None:
45-
"""Basic CWL v1.0 to CWL v1.1 test."""
44+
def test_v1_0_to_v1_1_load_listing(tmp_path: Path) -> None:
45+
"""Basic CWL v1.0 to CWL v1.1 test with LoadListingRequirement (map notation)."""
4646
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1.cwl"))
4747
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
48-
assert doc == upgraded
48+
expected = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
49+
assert upgraded == expected
50+
51+
52+
def test_v1_0_to_v1_1_load_listing_arr(tmp_path: Path) -> None:
53+
"""Basic CWL v1.0 to CWL v1.1 test with LoadListingRequirement (array notation)."""
54+
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1-arr.cwl"))
55+
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
56+
expected = load_cwl_document(get_data("testdata/v1.1/listing_deep1-arr.cwl"))
57+
assert upgraded == expected
58+
59+
60+
def test_v1_0_to_v1_1_network_access(tmp_path: Path) -> None:
61+
"""Basic CWL v1.0 to CWL v1.1 test with NetworkAccess."""
62+
doc = load_cwl_document(get_data("testdata/v1.0/networkaccess.cwl"))
63+
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
64+
expected = load_cwl_document(get_data("testdata/v1.1/networkaccess.cwl"))
65+
assert upgraded == expected
4966

5067

5168
def test_v1_1_to_v1_2(tmp_path: Path) -> None:
5269
"""Basic CWL v1.1 to CWL v1.2 test."""
5370
doc = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
5471
upgraded = upgrade_document(doc, str(tmp_path), "v1.2")
55-
assert doc == upgraded
72+
expected = load_cwl_document(get_data("testdata/v1.2/listing_deep1.cwl"))
73+
assert upgraded == expected
5674

5775

5876
def test_packed_graph(tmp_path: Path) -> None:
5977
"""Test packed document with $graph."""
60-
main(
61-
[f"--dir={tmp_path}", "--v1.1-only", get_data("testdata/v1.0/conflict-wf.cwl")]
62-
)
78+
main([f"--dir={tmp_path}", "--v1.1-only", get_data("testdata/v1.0/conflict-wf.cwl")])
6379
assert filecmp.cmp(
6480
get_data("testdata/v1.1/conflict-wf.cwl"),
6581
tmp_path / "conflict-wf.cwl",

0 commit comments

Comments
 (0)