Skip to content

Commit 7266ad4

Browse files
tom-tanmr-c
authored andcommitted
Handling invalid output object from engines
1 parent 2eb1537 commit 7266ad4

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

cwltest/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,23 @@ def run_test_plain(
422422
" ".join([shlex.quote(tc) for tc in test_command]),
423423
)
424424
raise
425+
except json.JSONDecodeError:
426+
logger.error(
427+
"""Test %s failed: %s""",
428+
number,
429+
" ".join([shlex.quote(tc) for tc in test_command]),
430+
)
431+
logger.error(test.get("doc", "").replace("\n", " ").strip())
432+
invalid_json_msg = "Output is not a valid JSON document: '%s'" % outstr
433+
logger.error(invalid_json_msg)
434+
return TestResult(
435+
1,
436+
outstr,
437+
outerr,
438+
duration,
439+
config.classname,
440+
invalid_json_msg,
441+
)
425442
except subprocess.TimeoutExpired:
426443
logger.error(
427444
"""Test %s timed out: %s""",

tests/test-data/dummy-executor.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
echo "it is not JSON format!"

tests/test-data/empty.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

tests/test-data/nothing.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- job: empty.yml
2+
tool: true.cwl
3+
output: {}
4+
id: do_nothing
5+
doc: Example of doing nothing
6+
- job: empty.yml
7+
tool: true.cwl
8+
output: {}
9+
id: do_nothing2
10+
doc: Example of doing nothing more

tests/test-data/true.cwl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.0
3+
inputs: {}
4+
outputs: {}
5+
baseCommand: ["true"]

tests/test_invalid_outputs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pathlib import Path
2+
3+
import schema_salad.ref_resolver
4+
5+
from .util import get_data, run_with_mock_cwl_runner
6+
7+
8+
def test_invalid_outputs(tmp_path: Path) -> None:
9+
args = [
10+
"--test",
11+
schema_salad.ref_resolver.file_uri(get_data("tests/test-data/nothing.yml")),
12+
]
13+
error_code, stdout, stderr = run_with_mock_cwl_runner(
14+
args, get_data("tests/test-data/dummy-executor.sh")
15+
)
16+
assert error_code == 1
17+
assert "0 tests passed, 2 failures, 0 unsupported features" in stderr

tests/util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import subprocess # nosec
66
from contextlib import ExitStack
77
from pathlib import Path
8-
from typing import List, Tuple
8+
from typing import List, Optional, Tuple
99

1010
from cwltest.utils import as_file, files
1111

@@ -28,9 +28,12 @@ def get_data(filename: str) -> str:
2828
return str(filepath.resolve())
2929

3030

31-
def run_with_mock_cwl_runner(args: List[str]) -> Tuple[int, str, str]:
31+
def run_with_mock_cwl_runner(
32+
args: List[str], cwl_runner: Optional[str] = None
33+
) -> Tuple[int, str, str]:
3234
"""Bind a mock cwlref-runner implementation to cwltest."""
33-
cwl_runner = get_data("tests/test-data/mock_cwl_runner.py")
35+
if cwl_runner is None:
36+
cwl_runner = get_data("tests/test-data/mock_cwl_runner.py")
3437
process = subprocess.Popen( # nosec
3538
["cwltest", "--tool", cwl_runner] + args,
3639
stdout=subprocess.PIPE,

0 commit comments

Comments
 (0)