Skip to content

Commit

Permalink
Fix tests for upgrade_document (#85)
Browse files Browse the repository at this point in the history
* Add test for NetworkAccess

* Add test for requirements in array notation
  • Loading branch information
tom-tan authored Nov 16, 2021
1 parent e2a05df commit df84c39
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 24 deletions.
18 changes: 9 additions & 9 deletions cwlupgrader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,29 +366,29 @@ def _v1_0_to_v1_1(document: CommentedMap, outdir: str) -> CommentedMap:
move_up_loadcontents(document)
network_access = has_hint_or_req(document, "NetworkAccess")
listing = has_hint_or_req(document, "LoadListingRequirement")
hints = document.get("hints", {})
reqs = document.get("requirements", {})
# TODO: add comments to explain the extra hints
if isinstance(hints, MutableSequence):
if isinstance(reqs, MutableSequence):
if not network_access:
hints.append({"class": "NetworkAccess", "networkAccess": True})
reqs.append({"class": "NetworkAccess", "networkAccess": True})
if not listing:
hints.append(
reqs.append(
cmap(
{
"class": "LoadListingRequirement",
"loadListing": "deep_listing",
}
)
)
elif isinstance(hints, MutableMapping):
elif isinstance(reqs, MutableMapping):
if not network_access:
hints["NetworkAccess"] = {"networkAccess": True}
reqs["NetworkAccess"] = {"networkAccess": True}
if not listing:
hints["LoadListingRequirement"] = cmap(
reqs["LoadListingRequirement"] = cmap(
{"loadListing": "deep_listing"}
)
if "hints" not in document:
document["hints"] = hints
if "requirements" not in document:
document["requirements"] = reqs
elif document["class"] == "ExpressionTool":
move_up_loadcontents(document)
cleanup_v1_0_input_bindings(document)
Expand Down
13 changes: 13 additions & 0 deletions testdata/v1.0/listing_deep1-arr.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.0
requirements:
- class: InlineJavascriptRequirement
inputs:
d: Directory
outputs:
out:
type: boolean
outputBinding:
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
baseCommand: "true"
10 changes: 10 additions & 0 deletions testdata/v1.0/networkaccess.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class: CommandLineTool
cwlVersion: v1.0
inputs: []
outputs: []
baseCommand: python
arguments:
- "-c"
- valueFrom: |
import urllib.request
assert(urllib.request.urlopen("http://commonwl.org").code == 200)
18 changes: 10 additions & 8 deletions testdata/v1.1/conflict-wf.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ $graph:
hints:
ResourceRequirement:
ramMin: 8
NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
inputs:
text:
type: string
Expand All @@ -24,16 +20,17 @@ $graph:
baseCommand: echo
stdout: out.txt

requirements:
NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
- id: cat
class: CommandLineTool
hints:
ResourceRequirement:
ramMin: 8

NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
inputs:
file1:
type: File
Expand All @@ -53,6 +50,11 @@ $graph:
baseCommand: cat
stdout: out.txt

requirements:
NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
- class: Workflow
id: collision

Expand Down
17 changes: 17 additions & 0 deletions testdata/v1.1/listing_deep1-arr.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env cwl-runner
class: CommandLineTool
cwlVersion: v1.1
requirements:
- class: InlineJavascriptRequirement
- class: NetworkAccess
networkAccess: true
- class: LoadListingRequirement
loadListing: deep_listing
inputs:
d: Directory
outputs:
out:
type: boolean
outputBinding:
outputEval: '$(inputs.d.listing.length === 1 && inputs.d.listing[0].listing.length === 1)'
baseCommand: "true"
2 changes: 2 additions & 0 deletions testdata/v1.1/listing_deep1.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ requirements:
LoadListingRequirement:
loadListing: deep_listing
InlineJavascriptRequirement: {}
NetworkAccess:
networkAccess: true
inputs:
d: Directory
outputs:
Expand Down
15 changes: 15 additions & 0 deletions testdata/v1.1/networkaccess.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class: CommandLineTool
cwlVersion: v1.1
requirements:
NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
inputs: []
outputs: []
baseCommand: python
arguments:
- "-c"
- valueFrom: |
import urllib.request
assert(urllib.request.urlopen("http://commonwl.org").code == 200)
2 changes: 2 additions & 0 deletions testdata/v1.2/listing_deep1.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ requirements:
LoadListingRequirement:
loadListing: deep_listing
InlineJavascriptRequirement: {}
NetworkAccess:
networkAccess: true
inputs:
d: Directory
outputs:
Expand Down
15 changes: 15 additions & 0 deletions testdata/v1.2/networkaccess.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class: CommandLineTool
cwlVersion: v1.2
requirements:
NetworkAccess:
networkAccess: true
LoadListingRequirement:
loadListing: deep_listing
inputs: []
outputs: []
baseCommand: python
arguments:
- "-c"
- valueFrom: |
import urllib.request
assert(urllib.request.urlopen("http://commonwl.org").code == 200)
30 changes: 23 additions & 7 deletions tests/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,41 @@ def test_invalid_target(tmp_path: Path) -> None:
assert result is None


def test_v1_0_to_v1_1(tmp_path: Path) -> None:
"""Basic CWL v1.0 to CWL v1.1 test."""
def test_v1_0_to_v1_1_load_listing(tmp_path: Path) -> None:
"""Basic CWL v1.0 to CWL v1.1 test with LoadListingRequirement (map notation)."""
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
assert doc == upgraded
expected = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
assert upgraded == expected


def test_v1_0_to_v1_1_load_listing_arr(tmp_path: Path) -> None:
"""Basic CWL v1.0 to CWL v1.1 test with LoadListingRequirement (array notation)."""
doc = load_cwl_document(get_data("testdata/v1.0/listing_deep1-arr.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
expected = load_cwl_document(get_data("testdata/v1.1/listing_deep1-arr.cwl"))
assert upgraded == expected


def test_v1_0_to_v1_1_network_access(tmp_path: Path) -> None:
"""Basic CWL v1.0 to CWL v1.1 test with NetworkAccess."""
doc = load_cwl_document(get_data("testdata/v1.0/networkaccess.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.1")
expected = load_cwl_document(get_data("testdata/v1.1/networkaccess.cwl"))
assert upgraded == expected


def test_v1_1_to_v1_2(tmp_path: Path) -> None:
"""Basic CWL v1.1 to CWL v1.2 test."""
doc = load_cwl_document(get_data("testdata/v1.1/listing_deep1.cwl"))
upgraded = upgrade_document(doc, str(tmp_path), "v1.2")
assert doc == upgraded
expected = load_cwl_document(get_data("testdata/v1.2/listing_deep1.cwl"))
assert upgraded == expected


def test_packed_graph(tmp_path: Path) -> None:
"""Test packed document with $graph."""
main(
[f"--dir={tmp_path}", "--v1.1-only", get_data("testdata/v1.0/conflict-wf.cwl")]
)
main([f"--dir={tmp_path}", "--v1.1-only", get_data("testdata/v1.0/conflict-wf.cwl")])
assert filecmp.cmp(
get_data("testdata/v1.1/conflict-wf.cwl"),
tmp_path / "conflict-wf.cwl",
Expand Down

0 comments on commit df84c39

Please sign in to comment.