Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cwltool/load_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -161,12 +162,17 @@ 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"])
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: <version>")

if workflowobj["cwlVersion"] == "draft-2":
workflowobj = cast(CommentedMap, cmap(update._draft2toDraft3dev1(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cwl_version.py
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions tests/wf/missing_cwlVersion.cwl
Original file line number Diff line number Diff line change
@@ -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]
32 changes: 32 additions & 0 deletions tests/wf/wrong_cwlVersion.cwl
Original file line number Diff line number Diff line change
@@ -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]