Skip to content

Commit

Permalink
ensure all test data is loaded flexibly
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Dec 28, 2016
1 parent 6a02920 commit a37b623
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions schema_salad/tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand All @@ -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
15 changes: 2 additions & 13 deletions schema_salad/tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)


Expand Down
13 changes: 13 additions & 0 deletions schema_salad/tests/util.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a37b623

Please sign in to comment.