diff --git a/schema_salad/tests/test_errors.py b/schema_salad/tests/test_errors.py index 79f3d6035..25a5eea8c 100644 --- a/schema_salad/tests/test_errors.py +++ b/schema_salad/tests/test_errors.py @@ -1,3 +1,4 @@ +from .util import get_data import unittest from typing import cast from schema_salad.schema import load_schema, load_and_validate @@ -7,7 +8,7 @@ class TestErrors(unittest.TestCase): def test_errors(self): document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema( - u"schema_salad/tests/test_schema/CommonWorkflowLanguage.yml") + get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")) avsc_names = cast(Names, avsc_names) for t in ("test_schema/test1.cwl", @@ -23,7 +24,8 @@ def test_errors(self): "test_schema/test11.cwl"): with self.assertRaises(ValidationException): try: - load_and_validate(document_loader, avsc_names, unicode("schema_salad/tests/"+t), True) + load_and_validate(document_loader, avsc_names, + unicode(get_data("tests/"+t)), True) except ValidationException as e: print "\n", e raise diff --git a/schema_salad/tests/test_examples.py b/schema_salad/tests/test_examples.py index 9191f515c..949bc6767 100644 --- a/schema_salad/tests/test_examples.py +++ b/schema_salad/tests/test_examples.py @@ -1,9 +1,9 @@ +from .util import get_data import unittest import schema_salad.ref_resolver import schema_salad.main import schema_salad.schema from schema_salad.jsonld_context import makerdf -from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore import rdflib import ruamel.yaml import json @@ -17,17 +17,6 @@ from ruamel.yaml.comments import CommentedSeq, CommentedMap -def get_data(filename): - filepath = None - try: - filepath = resource_filename( - Requirement.parse("schema-salad"), filename) - except ResolutionError: - pass - if not filepath or not os.path.isfile(filepath): - filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename) - return filepath - class TestSchemas(unittest.TestCase): def test_schemas(self): @@ -370,7 +359,7 @@ def test_mixin(self): def test_fragment(self): ldr = schema_salad.ref_resolver.Loader({"id": "@id"}) - b, _ = ldr.resolve_ref("schema_salad/tests/frag.yml#foo2") + b, _ = ldr.resolve_ref(get_data("tests/frag.yml#foo2")) self.assertEquals({"id": b["id"], "bar":"b2"}, b) diff --git a/schema_salad/tests/util.py b/schema_salad/tests/util.py new file mode 100644 index 000000000..0fcaf526e --- /dev/null +++ b/schema_salad/tests/util.py @@ -0,0 +1,13 @@ +from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore +import os + +def get_data(filename): + filepath = None + try: + filepath = resource_filename( + Requirement.parse("schema-salad"), filename) + except ResolutionError: + pass + if not filepath or not os.path.isfile(filepath): + filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename) + return filepath