Skip to content

Commit 0a48bd0

Browse files
author
Anton Khodak
committed
Improve error message for invalid outputs and add tests
1 parent 010dd97 commit 0a48bd0

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

cwltool/load_tool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from avro.schema import Names
2121
from ruamel.yaml.comments import CommentedMap, CommentedSeq
2222
from schema_salad.ref_resolver import ContextType, Fetcher, Loader, file_uri
23-
from schema_salad.sourceline import cmap
23+
from schema_salad.sourceline import cmap, SourceLine
2424
from schema_salad.validate import ValidationException
2525

2626
from . import process, update
@@ -125,7 +125,9 @@ def _convert_stdstreams_to_files(workflowobj):
125125
if workflowobj.get('class') == 'CommandLineTool':
126126
for out in workflowobj.get('outputs', []):
127127
if type(out) is not CommentedMap:
128-
raise ValidationException("Output '%s' is not valid" % out)
128+
with SourceLine(workflowobj, "outputs", ValidationException, _logger.isEnabledFor(logging.DEBUG)):
129+
raise ValidationException("Output '%s' is not a valid CWL type, "
130+
"check the outputs section of your tool" % out)
129131
for streamtype in ['stdout', 'stderr']:
130132
if out.get('type') == streamtype:
131133
if 'outputBinding' in out:

tests/test_examples.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ def test_lifting(self):
514514
echo = f.make(get_data("tests/test_bad_outputs_wf.cwl"))
515515
self.assertEqual(echo(inp="foo"), {"out": "foo\n"})
516516

517+
def test_malformed_outputs(self):
518+
# check that tool validation fails if one of the outputs is not a valid CWL type
519+
f = cwltool.factory.Factory()
520+
with self.assertRaises(schema_salad.validate.ValidationException):
521+
echo = f.make(get_data("tests/wf/malformed_outputs.cwl"))
522+
echo()
523+
524+
def test_separate_without_prefix(self):
525+
# check that setting 'separate = false' on an inputBinding without prefix does not fail the workflow
526+
f = cwltool.factory.Factory()
527+
echo = f.make(get_data("tests/wf/separate_without_prefix.cwl"))
528+
self.assertEqual(echo(), {"output": "string\n"})
529+
517530

518531
def test_checker(self):
519532
# check that the static checker raises exception when a source type

tests/wf/malformed_outputs.cwl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand: echo
4+
5+
inputs:
6+
[]
7+
outputs:
8+
-

tests/wf/separate_without_prefix.cwl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand: echo
4+
5+
inputs:
6+
src:
7+
type: string
8+
default:
9+
string
10+
inputBinding:
11+
position: 1
12+
separate: false
13+
14+
stdout: output.txt
15+
16+
outputs:
17+
output:
18+
type: string
19+
outputBinding:
20+
glob: output.txt
21+
loadContents: true
22+
outputEval: $(self[0].contents)

0 commit comments

Comments
 (0)