Skip to content

Commit a3e3a57

Browse files
committed
check for empty hints/reqs
1 parent feda254 commit a3e3a57

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

cwltool/process.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,15 @@ def __init__(
578578
self.names = make_avro_schema([SCHEMA_FILE, SCHEMA_DIR, SCHEMA_ANY], Loader({}))
579579
self.tool = toolpath_object
580580
self.requirements = copy.deepcopy(getdefault(loadingContext.requirements, []))
581-
self.requirements.extend(self.tool.get("requirements", []))
581+
tool_requirements = self.tool.get("requirements", [])
582+
if tool_requirements is None:
583+
raise ValidationException(
584+
SourceLine(self.tool, "requirements").makeError(
585+
"If 'requirements' is present then it must be a list "
586+
"or map/dictionary, not empty."
587+
)
588+
)
589+
self.requirements.extend(tool_requirements)
582590
if "id" not in self.tool:
583591
self.tool["id"] = "_:" + str(uuid.uuid4())
584592
self.requirements.extend(
@@ -590,7 +598,15 @@ def __init__(
590598
)
591599
)
592600
self.hints = copy.deepcopy(getdefault(loadingContext.hints, []))
593-
self.hints.extend(self.tool.get("hints", []))
601+
tool_hints = self.tool.get("hints", [])
602+
if tool_hints is None:
603+
raise ValidationException(
604+
SourceLine(self.tool, "hints").makeError(
605+
"If 'hints' is present then it must be a list "
606+
"or map/dictionary, not empty."
607+
)
608+
)
609+
self.hints.extend(tool_hints)
594610
# Versions of requirements and hints which aren't mutated.
595611
self.original_requirements = copy.deepcopy(self.requirements)
596612
self.original_hints = copy.deepcopy(self.hints)

tests/test_examples.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,3 +1398,23 @@ def test_scatter_output_filenames(tmp_path: Path) -> None:
13981398
and locations[1].endswith("output.txt_2")
13991399
and locations[2].endswith("output.txt_3")
14001400
), f"Locations {locations} do not end with {output_names}"
1401+
1402+
1403+
def test_malformed_hints() -> None:
1404+
"""Confirm that empty hints section is caught."""
1405+
factory = cwltool.factory.Factory()
1406+
with pytest.raises(
1407+
ValidationException,
1408+
match=r".*wc-tool-bad-hints\.cwl:6:1: If 'hints' is\s*present\s*then\s*it\s*must\s*be\s*a\s*list.*",
1409+
):
1410+
factory.make(get_data("tests/wc-tool-bad-hints.cwl"))
1411+
1412+
1413+
def test_malformed_reqs() -> None:
1414+
"""Confirm that empty reqs section is caught."""
1415+
factory = cwltool.factory.Factory()
1416+
with pytest.raises(
1417+
ValidationException,
1418+
match=r".*wc-tool-bad-reqs\.cwl:6:1: If 'requirements' is\s*present\s*then\s*it\s*must\s*be\s*a\s*list.*",
1419+
):
1420+
factory.make(get_data("tests/wc-tool-bad-reqs.cwl"))

tests/wc-tool-bad-hints.cwl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.1
5+
6+
hints:
7+
8+
inputs:
9+
file1: File
10+
11+
outputs:
12+
output:
13+
type: File
14+
outputBinding: { glob: output }
15+
16+
baseCommand: [wc, -l]
17+
18+
stdin: $(inputs.file1.path)
19+
stdout: output

tests/wc-tool-bad-reqs.cwl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.1
5+
6+
requirements:
7+
8+
inputs:
9+
file1: File
10+
11+
outputs:
12+
output:
13+
type: File
14+
outputBinding: { glob: output }
15+
16+
baseCommand: [wc, -l]
17+
18+
stdin: $(inputs.file1.path)
19+
stdout: output

0 commit comments

Comments
 (0)