Skip to content

Commit e2fb052

Browse files
committed
helper utility to test cwl-inputs-schema-gen
1 parent 58814a2 commit e2fb052

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/jschema_validate.py

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

0 commit comments

Comments
 (0)