diff --git a/MANIFEST.in b/MANIFEST.in index e951ca2..46873cc 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include Makefile gittaggers.py +include cwltest/cwltest-schema.yml include cwltest/tests/* include cwltest/tests/test-data/* +include cwltest/tests/test-data/v1.0/* global-exclude *~ global-exclude *.pyc - diff --git a/cwltest/__init__.py b/cwltest/__init__.py index 2a6ab97..a2282e8 100755 --- a/cwltest/__init__.py +++ b/cwltest/__init__.py @@ -16,6 +16,8 @@ import ruamel.yaml as yaml import ruamel.yaml.scanner as yamlscanner import schema_salad.ref_resolver +import schema_salad.schema +import schema_salad.avro.schema import pkg_resources # part of setuptools import junit_xml @@ -49,6 +51,7 @@ def prepare_test_command( args, # type: List[str] testargs, # type: Optional[List[str]] test, # type: Dict[str, str] + cwd, # type: str verbose=False, # type: bool ): # type: (...) -> List[str] """ Turn the test into a command line. """ @@ -77,9 +80,18 @@ def prepare_test_command( test_command.extend(["--outdir={}".format(outdir)]) if not verbose: test_command.extend(["--quiet"]) - test_command.extend([os.path.normcase(test["tool"])]) - if test.get("job"): - test_command.append(os.path.normcase(test["job"])) + + cwd = schema_salad.ref_resolver.file_uri(cwd) + toolpath = test["tool"] + if toolpath.startswith(cwd): + toolpath = toolpath[len(cwd)+1:] + test_command.extend([os.path.normcase(toolpath)]) + + jobpath = test.get("job") + if jobpath: + if jobpath.startswith(cwd): + jobpath = jobpath[len(cwd)+1:] + test_command.append(os.path.normcase(jobpath)) return test_command @@ -106,8 +118,9 @@ def run_test( suffix = "\n" try: process = None # type: Optional[subprocess.Popen[str]] + cwd = os.getcwd() test_command = prepare_test_command( - args.tool, args.args, args.testargs, test, verbose + args.tool, args.args, args.testargs, test, cwd, verbose ) if test.get("short_name"): @@ -131,7 +144,7 @@ def run_test( start_time = time.time() stderr = subprocess.PIPE if not args.verbose else None - process = subprocess.Popen(test_command, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True) + process = subprocess.Popen(test_command, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True, cwd=cwd) outstr, outerr = process.communicate(timeout=timeout) return_code = process.poll() duration = time.time() - start_time @@ -342,8 +355,18 @@ def main(): # type: () -> int arg_parser().print_help() return 1 - with open(args.test) as f: - tests = yaml.load(f, Loader=yaml.SafeLoader) + schema_resource = pkg_resources.resource_stream(__name__, "cwltest-schema.yml") + cache = {"https://w3id.org/cwl/cwltest/cwltest-schema.yml": schema_resource.read().decode("utf-8")} + (document_loader, + avsc_names, + schema_metadata, + metaschema_loader) = schema_salad.schema.load_schema("https://w3id.org/cwl/cwltest/cwltest-schema.yml", cache=cache) + + if not isinstance(avsc_names, schema_salad.avro.schema.Names): + print(avsc_names) + return 1 + + tests, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, args.test, True) failures = 0 unsupported = 0 @@ -378,6 +401,10 @@ def main(): # type: () -> int if any((tag in ts for tag in tags)): tests.append(t) + for t in tests: + if t.get("label"): + t["short_name"] = t["label"] + if args.l: for i, t in enumerate(tests): if t.get("short_name"): diff --git a/cwltest/cwltest-schema.yml b/cwltest/cwltest-schema.yml new file mode 100644 index 0000000..e084a75 --- /dev/null +++ b/cwltest/cwltest-schema.yml @@ -0,0 +1,26 @@ +$base: "https://w3id.org/cwl/cwltest#" +$graph: + - name: TestCase + type: record + documentRoot: true + fields: + id: + type: ["null", int, string] + jsonldPredicate: + _type: "@id" + identity: true + label: string? + short_name: string? + doc: string? + tags: string[]? + tool: + type: string + jsonldPredicate: + _type: "@id" + job: + type: string? + jsonldPredicate: + _type: "@id" + should_fail: boolean? + output: + type: Any? diff --git a/cwltest/tests/mock_cwl_runner.py b/cwltest/tests/mock_cwl_runner.py index 0188c9b..a352f7d 100644 --- a/cwltest/tests/mock_cwl_runner.py +++ b/cwltest/tests/mock_cwl_runner.py @@ -16,9 +16,9 @@ def main(): # type: ()->int args = parser.parse_args() - if args.processfile == UNSUPPORTED_FEATURE_TOOL: + if args.processfile.endswith(UNSUPPORTED_FEATURE_TOOL): exit(UNSUPPORTED_FEATURE) - elif args.processfile == ERROR_TOOL: + elif args.processfile.endswith(ERROR_TOOL): exit(1) exit(0) diff --git a/cwltest/tests/test-data/return-0.cwl b/cwltest/tests/test-data/return-0.cwl new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test-data/return-1.cwl b/cwltest/tests/test-data/return-1.cwl new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test-data/return-unsupported.cwl b/cwltest/tests/test-data/return-unsupported.cwl new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test-data/short-names.yml b/cwltest/tests/test-data/short-names.yml index 4cf6a8e..3f9c59f 100644 --- a/cwltest/tests/test-data/short-names.yml +++ b/cwltest/tests/test-data/short-names.yml @@ -2,6 +2,5 @@ output: {} tool: return-0.cwl doc: Test with a short name - short_name: opt-error + label: opt-error tags: [ js, init_work_dir ] - diff --git a/cwltest/tests/test-data/v1.0/cat-job.json b/cwltest/tests/test-data/v1.0/cat-job.json new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test-data/v1.0/cat1-job.json b/cwltest/tests/test-data/v1.0/cat1-job.json new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test-data/v1.0/cat2-job.json b/cwltest/tests/test-data/v1.0/cat2-job.json new file mode 100644 index 0000000..e69de29 diff --git a/cwltest/tests/test_categories.py b/cwltest/tests/test_categories.py index 0956db8..3ec6719 100644 --- a/cwltest/tests/test_categories.py +++ b/cwltest/tests/test_categories.py @@ -6,12 +6,20 @@ from .util import run_with_mock_cwl_runner, get_data import xml.etree.ElementTree as ET - +import schema_salad.ref_resolver class TestCategories(unittest.TestCase): + maxDiff = None + def test_unsupported_with_required_tests(self): - args = ["--test", get_data("tests/test-data/required-unsupported.yml")] - error_code, stdout, stderr = run_with_mock_cwl_runner(args) + args = ["--test", schema_salad.ref_resolver.file_uri(get_data("tests/test-data/required-unsupported.yml"))] + try: + cwd = os.getcwd() + os.chdir(get_data("tests/test-data/")) + error_code, stdout, stderr = run_with_mock_cwl_runner(args) + finally: + os.chdir(cwd) + self.assertEqual(error_code, 1) print(stderr) stderr = re.sub(r" '?--outdir=[^ ]*", "", stderr) @@ -39,7 +47,7 @@ def test_unsupported_with_required_tests(self): ) def test_unsupported_with_optional_tests(self): - args = ["--test", get_data("tests/test-data/optional-unsupported.yml")] + args = ["--test", schema_salad.ref_resolver.file_uri(get_data("tests/test-data/optional-unsupported.yml"))] error_code, stdout, stderr = run_with_mock_cwl_runner(args) self.assertEqual(error_code, 0) self.assertEqual( @@ -50,7 +58,7 @@ def test_unsupported_with_optional_tests(self): ) def test_error_with_optional_tests(self): - args = ["--test", get_data("tests/test-data/optional-error.yml")] + args = ["--test", schema_salad.ref_resolver.file_uri(get_data("tests/test-data/optional-error.yml"))] error_code, stdout, stderr = run_with_mock_cwl_runner(args) self.assertEqual(error_code, 1) self.assertIn("1 failures", stderr) @@ -59,7 +67,7 @@ def test_category_in_junit_xml(self): junit_xml_report = get_data("tests/test-data/junit-report.xml") args = [ "--test", - get_data("tests/test-data/optional-error.yml"), + schema_salad.ref_resolver.file_uri(get_data("tests/test-data/optional-error.yml")), "--junit-xml", junit_xml_report, ] diff --git a/cwltest/tests/test_prepare.py b/cwltest/tests/test_prepare.py index bd7e738..3d93487 100644 --- a/cwltest/tests/test_prepare.py +++ b/cwltest/tests/test_prepare.py @@ -19,6 +19,7 @@ def test_unix_relative_path(self): "job": "v1.0/bwa-mem-job.json", "tags": ["required"], }, + cwd=os.getcwd() ) if os.name == "nt": self.assertEqual(command[3], "v1.0\\bwa-mem-tool.cwl") diff --git a/setup.py b/setup.py index 054398b..feb50ae 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ except ImportError: tagger = egg_info_cmd.egg_info -install_requires = ["schema-salad >= 2", "junit-xml >= 1.8"] +install_requires = ["schema-salad >= 5.0.20200220195218", "junit-xml >= 1.8"] needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv) pytest_runner = ["pytest < 6", "pytest-runner < 5"] if needs_pytest else []