Skip to content

Commit

Permalink
Workflow checker: ignore 'null' when comparing arrays of types
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Sep 6, 2022
1 parent f43ca87 commit 87f3b01
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cwltool/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def can_assign_src_to_sink(
src: admissible source types
sink: admissible sink types
In non-strict comparison, at least one source type must match one sink type.
In non-strict comparison, at least one source type must match one sink type,
except for 'null'.
In strict comparison, all source types must match at least one sink type.
"""
if src == "Any" or sink == "Any":
Expand Down Expand Up @@ -119,7 +120,9 @@ def can_assign_src_to_sink(
return False
return True
for this_src in src:
if can_assign_src_to_sink(cast(SinkType, this_src), sink):
if this_src != "null" and can_assign_src_to_sink(
cast(SinkType, this_src), sink
):
return True
return False
if isinstance(sink, MutableSequence):
Expand Down
21 changes: 21 additions & 0 deletions tests/checker_wf/optional_array_mismatch.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cwlVersion: v1.0
class: Workflow
inputs:
first_wf_input: string[]?

steps:
first_step:
run:
class: CommandLineTool
inputs:
first_clt_input:
type: File[]?
inputBinding:
position: 1
baseCommand: [ ls, -l ]
outputs: []
in:
first_clt_input: first_wf_input
out: []

outputs: []
19 changes: 19 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,3 +1788,22 @@ def tests_outputsource_valid_identifier_invalid_source() -> None:
stderr = re.sub(r"\s\s+", " ", stderr)
assert "tests/checker_wf/broken-wf4.cwl:12:5: outputSource not found" in stderr
assert "tests/checker_wf/broken-wf4.cwl#echo_w" in stderr


def test_mismatched_optional_arrays() -> None:
"""Ignore 'null' when comparing array types."""
factory = cwltool.factory.Factory()

with pytest.raises(ValidationException):
factory.make(get_data("tests/checker_wf/optional_array_mismatch.cwl"))


def test_validate_optional_src_with_mandatory_sink() -> None:
"""Confirm expected warning with an optional File connected to a mandatory File."""
exit_code, stdout, stderr = get_main_output(
["--validate", get_data("tests/wf/optional_src_mandatory_sink.cwl")]
)
assert exit_code == 0
stderr = re.sub(r"\s\s+", " ", stderr)
assert 'Source \'opt_file\' of type ["null", "File"] may be incompatible' in stderr
assert "with sink 'r' of type \"File\"" in stderr
15 changes: 15 additions & 0 deletions tests/wf/optional_src_mandatory_sink.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0
class: Workflow

inputs:
opt_file: File?

steps:
my_only_step:
run: ./cat.cwl
in:
r: opt_file
out: []

outputs: []

0 comments on commit 87f3b01

Please sign in to comment.