Skip to content

Commit 85709d1

Browse files
authored
Merge pull request #104 from common-workflow-language/use-schema-salad
Use schema salad
2 parents 221e21c + ba52fe6 commit 85709d1

14 files changed

+81
-19
lines changed

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include Makefile gittaggers.py
2+
include cwltest/cwltest-schema.yml
23
include cwltest/tests/*
34
include cwltest/tests/test-data/*
5+
include cwltest/tests/test-data/v1.0/*
46
global-exclude *~
57
global-exclude *.pyc
6-

cwltest/__init__.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import ruamel.yaml as yaml
1717
import ruamel.yaml.scanner as yamlscanner
1818
import schema_salad.ref_resolver
19+
import schema_salad.schema
20+
import schema_salad.avro.schema
1921
import pkg_resources # part of setuptools
2022

2123
import junit_xml
@@ -49,6 +51,7 @@ def prepare_test_command(
4951
args, # type: List[str]
5052
testargs, # type: Optional[List[str]]
5153
test, # type: Dict[str, str]
54+
cwd, # type: str
5255
verbose=False, # type: bool
5356
): # type: (...) -> List[str]
5457
""" Turn the test into a command line. """
@@ -77,9 +80,18 @@ def prepare_test_command(
7780
test_command.extend(["--outdir={}".format(outdir)])
7881
if not verbose:
7982
test_command.extend(["--quiet"])
80-
test_command.extend([os.path.normcase(test["tool"])])
81-
if test.get("job"):
82-
test_command.append(os.path.normcase(test["job"]))
83+
84+
cwd = schema_salad.ref_resolver.file_uri(cwd)
85+
toolpath = test["tool"]
86+
if toolpath.startswith(cwd):
87+
toolpath = toolpath[len(cwd)+1:]
88+
test_command.extend([os.path.normcase(toolpath)])
89+
90+
jobpath = test.get("job")
91+
if jobpath:
92+
if jobpath.startswith(cwd):
93+
jobpath = jobpath[len(cwd)+1:]
94+
test_command.append(os.path.normcase(jobpath))
8395
return test_command
8496

8597

@@ -106,8 +118,9 @@ def run_test(
106118
suffix = "\n"
107119
try:
108120
process = None # type: Optional[subprocess.Popen[str]]
121+
cwd = os.getcwd()
109122
test_command = prepare_test_command(
110-
args.tool, args.args, args.testargs, test, verbose
123+
args.tool, args.args, args.testargs, test, cwd, verbose
111124
)
112125

113126
if test.get("short_name"):
@@ -131,7 +144,7 @@ def run_test(
131144

132145
start_time = time.time()
133146
stderr = subprocess.PIPE if not args.verbose else None
134-
process = subprocess.Popen(test_command, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True)
147+
process = subprocess.Popen(test_command, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True, cwd=cwd)
135148
outstr, outerr = process.communicate(timeout=timeout)
136149
return_code = process.poll()
137150
duration = time.time() - start_time
@@ -342,8 +355,18 @@ def main(): # type: () -> int
342355
arg_parser().print_help()
343356
return 1
344357

345-
with open(args.test) as f:
346-
tests = yaml.load(f, Loader=yaml.SafeLoader)
358+
schema_resource = pkg_resources.resource_stream(__name__, "cwltest-schema.yml")
359+
cache = {"https://w3id.org/cwl/cwltest/cwltest-schema.yml": schema_resource.read().decode("utf-8")}
360+
(document_loader,
361+
avsc_names,
362+
schema_metadata,
363+
metaschema_loader) = schema_salad.schema.load_schema("https://w3id.org/cwl/cwltest/cwltest-schema.yml", cache=cache)
364+
365+
if not isinstance(avsc_names, schema_salad.avro.schema.Names):
366+
print(avsc_names)
367+
return 1
368+
369+
tests, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, args.test, True)
347370

348371
failures = 0
349372
unsupported = 0
@@ -378,6 +401,10 @@ def main(): # type: () -> int
378401
if any((tag in ts for tag in tags)):
379402
tests.append(t)
380403

404+
for t in tests:
405+
if t.get("label"):
406+
t["short_name"] = t["label"]
407+
381408
if args.l:
382409
for i, t in enumerate(tests):
383410
if t.get("short_name"):

cwltest/cwltest-schema.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
$base: "https://w3id.org/cwl/cwltest#"
2+
$graph:
3+
- name: TestCase
4+
type: record
5+
documentRoot: true
6+
fields:
7+
id:
8+
type: ["null", int, string]
9+
jsonldPredicate:
10+
_type: "@id"
11+
identity: true
12+
label: string?
13+
short_name: string?
14+
doc: string?
15+
tags: string[]?
16+
tool:
17+
type: string
18+
jsonldPredicate:
19+
_type: "@id"
20+
job:
21+
type: string?
22+
jsonldPredicate:
23+
_type: "@id"
24+
should_fail: boolean?
25+
output:
26+
type: Any?

cwltest/tests/mock_cwl_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def main(): # type: ()->int
1616

1717
args = parser.parse_args()
1818

19-
if args.processfile == UNSUPPORTED_FEATURE_TOOL:
19+
if args.processfile.endswith(UNSUPPORTED_FEATURE_TOOL):
2020
exit(UNSUPPORTED_FEATURE)
21-
elif args.processfile == ERROR_TOOL:
21+
elif args.processfile.endswith(ERROR_TOOL):
2222
exit(1)
2323

2424
exit(0)

cwltest/tests/test-data/return-0.cwl

Whitespace-only changes.

cwltest/tests/test-data/return-1.cwl

Whitespace-only changes.

cwltest/tests/test-data/return-unsupported.cwl

Whitespace-only changes.

cwltest/tests/test-data/short-names.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
output: {}
33
tool: return-0.cwl
44
doc: Test with a short name
5-
short_name: opt-error
5+
label: opt-error
66
tags: [ js, init_work_dir ]
7-

cwltest/tests/test-data/v1.0/cat-job.json

Whitespace-only changes.

cwltest/tests/test-data/v1.0/cat1-job.json

Whitespace-only changes.

0 commit comments

Comments
 (0)