Skip to content

Commit e648962

Browse files
committed
helper utility to test cwl-inputs-schema-gen
1 parent 9b569de commit e648962

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/jschema_validate.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import os
5+
import sys
6+
from pathlib import Path
7+
8+
from jsonschema.validators import validate
9+
from ruamel.yaml import YAML
10+
11+
from cwl_utils.inputs_schema_gen import cwl_to_jsonschema
12+
from cwl_utils.parser import load_document_by_uri
13+
14+
15+
def main() -> None:
16+
parser = argparse.ArgumentParser(description="test cwl-inputs-schema-gen.")
17+
parser.add_argument(
18+
"--outdir",
19+
type=str,
20+
default=os.path.abspath("."),
21+
help="Output directory. This is present only for cwltest's usage, and it is ignored.",
22+
)
23+
parser.add_argument(
24+
"--quiet", action="store_true", help="Only print warnings and errors."
25+
)
26+
parser.add_argument("--version", action="store_true", help="Print version and exit")
27+
parser.add_argument(
28+
"workflow",
29+
type=str,
30+
nargs="?",
31+
default=None,
32+
metavar="cwl_document",
33+
help="path or URL to a CWL Workflow, " "CommandLineTool, or ExpressionTool.",
34+
)
35+
parser.add_argument(
36+
"job_order",
37+
nargs=argparse.REMAINDER,
38+
metavar="inputs_object",
39+
help="path or URL to a YAML or JSON "
40+
"formatted description of the required input values for the given "
41+
"`cwl_document`.",
42+
)
43+
44+
args = parser.parse_args(sys.argv[1:])
45+
46+
if args.version:
47+
print(f"{sys.argv[1]} 0.0.1")
48+
return
49+
50+
if len(args.job_order) < 1:
51+
job_order = {}
52+
job_order_name = "empty inputs"
53+
else:
54+
yaml = YAML()
55+
job_order_name = args.job_order[0]
56+
job_order = yaml.load(Path(job_order_name))
57+
58+
validate(
59+
job_order,
60+
cwl_to_jsonschema(load_document_by_uri(args.workflow)),
61+
)
62+
63+
if not args.quiet:
64+
print(
65+
f"Validation of the JSON schema generated from {args.workflow} using {job_order_name} suceeded."
66+
)
67+
68+
69+
if __name__ == "__main__":
70+
main()

0 commit comments

Comments
 (0)