From 73ba4ffce57cf53f096b18b7ac817d52e0fb7c8f Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Sat, 22 Jul 2017 13:50:37 +0530 Subject: [PATCH 1/3] load_tool: when no version is found, raise Validation exception --- cwltool/load_tool.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cwltool/load_tool.py b/cwltool/load_tool.py index 986255364..182bbad22 100644 --- a/cwltool/load_tool.py +++ b/cwltool/load_tool.py @@ -165,8 +165,8 @@ def validate_document(document_loader, # type: Loader r"^(?:cwl:|https://w3id.org/cwl/cwl#)", "", workflowobj["cwlVersion"]) else: - _logger.warning("No cwlVersion found, treating this file as draft-2.") - workflowobj["cwlVersion"] = "draft-2" + raise ValidationException("No cwlVersion found." + "Use the following syntax in your CWL workflow to declare version: cwlVersion: ") if workflowobj["cwlVersion"] == "draft-2": workflowobj = cast(CommentedMap, cmap(update._draft2toDraft3dev1( From 2c762b536caa0062aaf26d81df7745e246a6a1cf Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Sun, 23 Jul 2017 14:51:22 +0530 Subject: [PATCH 2/3] load_tool.py: Raise validation exception when unsupported CWL Version is used --- cwltool/load_tool.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cwltool/load_tool.py b/cwltool/load_tool.py index 182bbad22..38573a2ed 100644 --- a/cwltool/load_tool.py +++ b/cwltool/load_tool.py @@ -22,6 +22,7 @@ from . import process, update from .errors import WorkflowException from .process import Process, shortname +from .update import ALLUPDATES _logger = logging.getLogger("cwltool") @@ -161,6 +162,11 @@ def validate_document(document_loader, # type: Loader if "cwlVersion" in workflowobj: if not isinstance(workflowobj["cwlVersion"], (str, Text)): raise Exception("'cwlVersion' must be a string, got %s" % type(workflowobj["cwlVersion"])) + if workflowobj["cwlVersion"] not in list(ALLUPDATES): + # print out all the Supported Versions of cwlVersion + versions = list(ALLUPDATES) # ALLUPDATES is a dict + versions.sort() + raise ValidationException("'cwlVersion' not valid. Supported CWL versions are: \n{}".format("\n".join(versions))) workflowobj["cwlVersion"] = re.sub( r"^(?:cwl:|https://w3id.org/cwl/cwl#)", "", workflowobj["cwlVersion"]) From c08ebbb1de59d447ab8e92a24c03f592d70d0ba9 Mon Sep 17 00:00:00 2001 From: Manvendra Singh Date: Sun, 23 Jul 2017 22:42:42 +0530 Subject: [PATCH 3/3] test_cwl_version.py: add tests for the cwlVersion quirks --- tests/test_cwl_version.py | 14 ++++++++++++++ tests/wf/missing_cwlVersion.cwl | 31 +++++++++++++++++++++++++++++++ tests/wf/wrong_cwlVersion.cwl | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 tests/test_cwl_version.py create mode 100644 tests/wf/missing_cwlVersion.cwl create mode 100644 tests/wf/wrong_cwlVersion.cwl diff --git a/tests/test_cwl_version.py b/tests/test_cwl_version.py new file mode 100644 index 000000000..c78a01375 --- /dev/null +++ b/tests/test_cwl_version.py @@ -0,0 +1,14 @@ +from __future__ import absolute_import +import unittest + +from cwltool.main import main + +from .util import get_data + +class CWL_Version_Checks(unittest.TestCase): + # no cwlVersion in the workflow + def test_missing_cwl_version(self): + self.assertEqual(main([get_data('tests/wf/missing_cwlVersion.cwl')]), 1) + # using cwlVersion: v0.1 in the workflow + def test_incorrect_cwl_version(self): + self.assertEqual(main([get_data('tests/wf/wrong_cwlVersion.cwl')]), 1) diff --git a/tests/wf/missing_cwlVersion.cwl b/tests/wf/missing_cwlVersion.cwl new file mode 100644 index 000000000..951842d36 --- /dev/null +++ b/tests/wf/missing_cwlVersion.cwl @@ -0,0 +1,31 @@ +#!/usr/bin/env cwl-runner +class: Workflow + +label: "Hello World" +doc: "Outputs a message using echo" + +inputs: [] + +outputs: + response: + outputSource: step0/response + type: File + +steps: + step0: + run: + class: CommandLineTool + inputs: + message: + type: string + doc: "The message to print" + default: "Hello World" + inputBinding: + position: 1 + baseCommand: echo + stdout: response.txt + outputs: + response: + type: stdout + in: [] + out: [response] diff --git a/tests/wf/wrong_cwlVersion.cwl b/tests/wf/wrong_cwlVersion.cwl new file mode 100644 index 000000000..3bac9583b --- /dev/null +++ b/tests/wf/wrong_cwlVersion.cwl @@ -0,0 +1,32 @@ +#!/usr/bin/env cwl-runner +cwlVersion: v0.1 +class: Workflow + +label: "Hello World" +doc: "Outputs a message using echo" + +inputs: [] + +outputs: + response: + outputSource: step0/response + type: File + +steps: + step0: + run: + class: CommandLineTool + inputs: + message: + type: string + doc: "The message to print" + default: "Hello World" + inputBinding: + position: 1 + baseCommand: echo + stdout: response.txt + outputs: + response: + type: stdout + in: [] + out: [response]