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
26 changes: 12 additions & 14 deletions cwltool/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,26 @@ def v1_0to1_1(
def rewrite_requirements(t: CWLObjectType) -> None:
if "requirements" in t:
for r in cast(MutableSequence[CWLObjectType], t["requirements"]):
if isinstance(r, MutableMapping):
cls = cast(str, r["class"])
if cls in rewrite:
r["class"] = rewrite[cls]
else:
raise ValidationException(
"requirements entries must be dictionaries: {} {}.".format(type(r), r)
)
cls = cast(str, r["class"])
if cls in rewrite:
r["class"] = rewrite[cls]
if "hints" in t:
for r in cast(MutableSequence[CWLObjectType], t["hints"]):
for index, r in enumerate(cast(MutableSequence[CWLObjectType], t["hints"])):
if isinstance(r, MutableMapping):
if "class" not in r:
raise SourceLine(r, None, ValidationException).makeError(
"'hints' entry missing required key 'class'."
)
cls = cast(str, r["class"])
if cls in rewrite:
r["class"] = rewrite[cls]
else:
raise ValidationException(f"hints entries must be dictionaries: {type(r)} {r}.")
raise SourceLine(t["hints"], index, ValidationException).makeError(
f"'hints' entries must be dictionaries: {type(r)} {r}."
)
if "steps" in t:
for s in cast(MutableSequence[CWLObjectType], t["steps"]):
if isinstance(s, MutableMapping):
rewrite_requirements(s)
else:
raise ValidationException(f"steps entries must be dictionaries: {type(s)} {s}.")
rewrite_requirements(s)

def update_secondaryFiles(
t: CWLOutputType, top: bool = False
Expand Down
23 changes: 23 additions & 0 deletions tests/test_load_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

import pytest
from schema_salad.exceptions import ValidationException

from cwltool.context import LoadingContext, RuntimeContext
from cwltool.errors import WorkflowException
Expand Down Expand Up @@ -143,3 +144,25 @@ def test_import_tracked() -> None:

assert tool.doc_loader is not None
assert path in tool.doc_loader.idx


def test_load_badhints() -> None:
"""Check for expected error while update a bads hints list."""
loadingContext = LoadingContext()
uri = Path(get_data("tests/wf/hello-workflow-badhints.cwl")).as_uri()
with pytest.raises(
ValidationException,
match=r".*tests\/wf\/hello-workflow-badhints\.cwl\:18:4:\s*'hints'\s*entry\s*missing\s*required\s*key\s*'class'\.",
):
load_tool(uri, loadingContext)


def test_load_badhints_nodict() -> None:
"""Check for expected error while update a hints list with a numerical entry."""
loadingContext = LoadingContext()
uri = Path(get_data("tests/wf/hello-workflow-badhints2.cwl")).as_uri()
with pytest.raises(
ValidationException,
match=r".*tests\/wf\/hello-workflow-badhints2\.cwl:41:5:\s*'hints'\s*entries\s*must\s*be\s*dictionaries:\s*<class\s*'int'>\s*42\.",
):
load_tool(uri, loadingContext)
41 changes: 41 additions & 0 deletions tests/wf/hello-workflow-badhints.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: Workflow

label: "Hello World"
doc: "Outputs a message using echo"

inputs:
usermessage: string

outputs:
response:
outputSource: step0/response
type: File

hints:
- {}

steps:
step0:
run:
class: CommandLineTool
inputs:
message:
type: string
doc: "The message to print"
default: "Hello World"
inputBinding:
position: 1
baseCommand: echo
arguments:
- "-n"
- "-e"
stdout: response.txt
outputs:
response:
type: stdout
in:
message: usermessage
out: [response]
41 changes: 41 additions & 0 deletions tests/wf/hello-workflow-badhints2.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: Workflow

label: "Hello World"
doc: "Outputs a message using echo"

inputs:
usermessage: string

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
arguments:
- "-n"
- "-e"
stdout: response.txt
outputs:
response:
type: stdout
in:
message: usermessage
out: [response]

hints:
- 42