Skip to content

Commit 2bf18be

Browse files
committed
more jsonschema inputs tests
1 parent 4e3a6c0 commit 2bf18be

File tree

6 files changed

+90
-1
lines changed

6 files changed

+90
-1
lines changed

testdata/echo-tool.cwl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: CommandLineTool
4+
cwlVersion: v1.2
5+
inputs:
6+
in:
7+
type: Any
8+
inputBinding: {}
9+
outputs:
10+
out:
11+
type: string
12+
outputBinding:
13+
glob: out.txt
14+
loadContents: true
15+
outputEval: $(self[0].contents)
16+
baseCommand: echo
17+
stdout: out.txt

testdata/empty.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"in": null
3+
}

testdata/null-expression1-job.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"i1": null
3+
}

testdata/null-expression2-tool.cwl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env cwl-runner
2+
3+
class: ExpressionTool
4+
requirements:
5+
- class: InlineJavascriptRequirement
6+
cwlVersion: v1.2
7+
8+
inputs:
9+
i1: Any
10+
11+
outputs:
12+
output: int
13+
14+
expression: "$({'output': (inputs.i1 == 'the-default' ? 1 : 2)})"

tests/test_inputs_schema_gen.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_cwl_inputs_to_jsonschema(tool_path: Path, inputs_path: Path) -> None:
7575
raise SchemaError(f"{inputs_path.name} failed schema validation") from err
7676

7777

78-
def test_cwl_inputs_to_jsonschema_fails() -> None:
78+
def test_cwl_inputs_to_jsonschema_single_fail() -> None:
7979
"""Compare tool schema of param 1 against input schema of param 2."""
8080
tool_path: Path = TEST_PARAMS[0][0]
8181
inputs_path: Path = TEST_PARAMS[3][1]
@@ -96,3 +96,54 @@ def test_cwl_inputs_to_jsonschema_fails() -> None:
9696
# We expect this to fail
9797
with pytest.raises(ValidationError):
9898
validate(input_obj, json_schema)
99+
100+
101+
BAD_TEST_PARAMS = [
102+
# Any without defaults cannot be unspecified
103+
(
104+
get_path("testdata/null-expression2-tool.cwl"),
105+
get_path("testdata/empty.json"),
106+
"'i1' is a required property",
107+
),
108+
# null to Any type without a default value.
109+
(
110+
get_path("testdata/null-expression2-tool.cwl"),
111+
get_path("testdata/null-expression1-job.json"),
112+
"None is not valid under any of the given schemas",
113+
),
114+
# Any without defaults, unspecified
115+
(
116+
get_path("testdata/echo-tool.cwl"),
117+
get_path("testdata/null-expression-echo-job.json"),
118+
"None is not valid under any of the given schemas",
119+
),
120+
# Dir
121+
(
122+
get_path("testdata/echo-tool.cwl"),
123+
get_path("testdata/null-expression1-job.json"),
124+
"'in' is a required property",
125+
),
126+
]
127+
128+
129+
@pytest.mark.parametrize("tool_path,inputs_path,exception_message", BAD_TEST_PARAMS)
130+
def test_cwl_inputs_to_jsonschema_fails(
131+
tool_path: Path,
132+
inputs_path: Path,
133+
exception_message: str,
134+
) -> None:
135+
cwl_obj = load_document_by_uri(tool_path.as_uri())
136+
137+
logger.info(f"Generating schema for {tool_path.name}")
138+
json_schema = cwl_to_jsonschema(cwl_obj)
139+
140+
logger.info(
141+
f"Testing {inputs_path.name} against schema generated for input {tool_path.name}"
142+
)
143+
144+
yaml = YAML()
145+
146+
input_obj = yaml.load(inputs_path)
147+
148+
with pytest.raises(ValidationError, match=exception_message):
149+
validate(input_obj, json_schema)

0 commit comments

Comments
 (0)