Skip to content

Commit a37b623

Browse files
committed
ensure all test data is loaded flexibly
1 parent 6a02920 commit a37b623

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

schema_salad/tests/test_errors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .util import get_data
12
import unittest
23
from typing import cast
34
from schema_salad.schema import load_schema, load_and_validate
@@ -7,7 +8,7 @@
78
class TestErrors(unittest.TestCase):
89
def test_errors(self):
910
document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
10-
u"schema_salad/tests/test_schema/CommonWorkflowLanguage.yml")
11+
get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))
1112
avsc_names = cast(Names, avsc_names)
1213

1314
for t in ("test_schema/test1.cwl",
@@ -23,7 +24,8 @@ def test_errors(self):
2324
"test_schema/test11.cwl"):
2425
with self.assertRaises(ValidationException):
2526
try:
26-
load_and_validate(document_loader, avsc_names, unicode("schema_salad/tests/"+t), True)
27+
load_and_validate(document_loader, avsc_names,
28+
unicode(get_data("tests/"+t)), True)
2729
except ValidationException as e:
2830
print "\n", e
2931
raise

schema_salad/tests/test_examples.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
from .util import get_data
12
import unittest
23
import schema_salad.ref_resolver
34
import schema_salad.main
45
import schema_salad.schema
56
from schema_salad.jsonld_context import makerdf
6-
from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore
77
import rdflib
88
import ruamel.yaml
99
import json
@@ -17,17 +17,6 @@
1717

1818
from ruamel.yaml.comments import CommentedSeq, CommentedMap
1919

20-
def get_data(filename):
21-
filepath = None
22-
try:
23-
filepath = resource_filename(
24-
Requirement.parse("schema-salad"), filename)
25-
except ResolutionError:
26-
pass
27-
if not filepath or not os.path.isfile(filepath):
28-
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
29-
return filepath
30-
3120

3221
class TestSchemas(unittest.TestCase):
3322
def test_schemas(self):
@@ -370,7 +359,7 @@ def test_mixin(self):
370359

371360
def test_fragment(self):
372361
ldr = schema_salad.ref_resolver.Loader({"id": "@id"})
373-
b, _ = ldr.resolve_ref("schema_salad/tests/frag.yml#foo2")
362+
b, _ = ldr.resolve_ref(get_data("tests/frag.yml#foo2"))
374363
self.assertEquals({"id": b["id"], "bar":"b2"}, b)
375364

376365

schema_salad/tests/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore
2+
import os
3+
4+
def get_data(filename):
5+
filepath = None
6+
try:
7+
filepath = resource_filename(
8+
Requirement.parse("schema-salad"), filename)
9+
except ResolutionError:
10+
pass
11+
if not filepath or not os.path.isfile(filepath):
12+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
13+
return filepath

0 commit comments

Comments
 (0)