Skip to content

Commit 87f3b01

Browse files
committed
Workflow checker: ignore 'null' when comparing arrays of types
1 parent f43ca87 commit 87f3b01

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

Diff for: cwltool/checker.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def can_assign_src_to_sink(
8181
src: admissible source types
8282
sink: admissible sink types
8383
84-
In non-strict comparison, at least one source type must match one sink type.
84+
In non-strict comparison, at least one source type must match one sink type,
85+
except for 'null'.
8586
In strict comparison, all source types must match at least one sink type.
8687
"""
8788
if src == "Any" or sink == "Any":
@@ -119,7 +120,9 @@ def can_assign_src_to_sink(
119120
return False
120121
return True
121122
for this_src in src:
122-
if can_assign_src_to_sink(cast(SinkType, this_src), sink):
123+
if this_src != "null" and can_assign_src_to_sink(
124+
cast(SinkType, this_src), sink
125+
):
123126
return True
124127
return False
125128
if isinstance(sink, MutableSequence):

Diff for: tests/checker_wf/optional_array_mismatch.cwl

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cwlVersion: v1.0
2+
class: Workflow
3+
inputs:
4+
first_wf_input: string[]?
5+
6+
steps:
7+
first_step:
8+
run:
9+
class: CommandLineTool
10+
inputs:
11+
first_clt_input:
12+
type: File[]?
13+
inputBinding:
14+
position: 1
15+
baseCommand: [ ls, -l ]
16+
outputs: []
17+
in:
18+
first_clt_input: first_wf_input
19+
out: []
20+
21+
outputs: []

Diff for: tests/test_examples.py

+19
Original file line numberDiff line numberDiff line change
@@ -1788,3 +1788,22 @@ def tests_outputsource_valid_identifier_invalid_source() -> None:
17881788
stderr = re.sub(r"\s\s+", " ", stderr)
17891789
assert "tests/checker_wf/broken-wf4.cwl:12:5: outputSource not found" in stderr
17901790
assert "tests/checker_wf/broken-wf4.cwl#echo_w" in stderr
1791+
1792+
1793+
def test_mismatched_optional_arrays() -> None:
1794+
"""Ignore 'null' when comparing array types."""
1795+
factory = cwltool.factory.Factory()
1796+
1797+
with pytest.raises(ValidationException):
1798+
factory.make(get_data("tests/checker_wf/optional_array_mismatch.cwl"))
1799+
1800+
1801+
def test_validate_optional_src_with_mandatory_sink() -> None:
1802+
"""Confirm expected warning with an optional File connected to a mandatory File."""
1803+
exit_code, stdout, stderr = get_main_output(
1804+
["--validate", get_data("tests/wf/optional_src_mandatory_sink.cwl")]
1805+
)
1806+
assert exit_code == 0
1807+
stderr = re.sub(r"\s\s+", " ", stderr)
1808+
assert 'Source \'opt_file\' of type ["null", "File"] may be incompatible' in stderr
1809+
assert "with sink 'r' of type \"File\"" in stderr

Diff for: tests/wf/optional_src_mandatory_sink.cwl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env cwl-runner
2+
cwlVersion: v1.0
3+
class: Workflow
4+
5+
inputs:
6+
opt_file: File?
7+
8+
steps:
9+
my_only_step:
10+
run: ./cat.cwl
11+
in:
12+
r: opt_file
13+
out: []
14+
15+
outputs: []

0 commit comments

Comments
 (0)