Skip to content

Commit

Permalink
Merge branch 'update-build-process' into 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwagner committed Mar 5, 2024
2 parents 95bccbc + e2d623d commit 3ba7ce1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
30 changes: 15 additions & 15 deletions tests/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from jsonschema import Draft202012Validator
import re

root_dir = Path(__file__).parent.parent
schema_dir = root_dir / "schema"
test_dir = root_dir / "tests"
examples_dir = root_dir / "examples"
vrs_source_path = schema_dir / "vrs" / "vrs-source.yaml"
vrs_jsons_path = schema_dir / "vrs" / "json"
root_path = Path(__file__).parent.parent
schema_path = root_path / "schema"
test_path = root_path / "tests"
examples_path = root_path / "examples"
vrs_source_path = schema_path / "vrs" / "vrs-source.yaml"
vrs_jsons_path = schema_path / "vrs" / "json"


ga4gh_re = re.compile(r'.*\/ga4gh\/schema\/([\w\-\.]+)\/[\w\.]+\/(.*)$')
Expand All @@ -22,25 +22,25 @@ def retrieve_rel_ref(ga4gh_ref: str):
raise ValueError(f'ga4gh_ref {ga4gh_ref} is not a root GA4GH reference')
schema_module = ga4gh_match.group(1)
local_path = ga4gh_match.group(2)
resolved_path = (schema_dir / schema_module / local_path).resolve()
resolved_path = (schema_path / schema_module / local_path).resolve()
schema = json.loads(resolved_path.read_text())
return Resource.from_contents(schema)


vrs_js_registry = Registry(retrieve=retrieve_rel_ref)
vrs_js = dict()
vrs_validator = dict()
js_registry = Registry(retrieve=retrieve_rel_ref)
js_def = dict()
validator = dict()

for schema_path in vrs_jsons_path.glob('*'):
for schema_path in schema_path.glob('*/json/*'):
content = json.loads(schema_path.read_text())
schema_uri = schema_path.as_uri()
content['id'] = schema_uri
schema_resource = Resource(contents=content, specification=DRAFT202012)
vrs_js[schema_path.stem] = content
vrs_schemas = vrs_js_registry.with_resources([
js_def[schema_path.stem] = content
js_registry = js_registry.with_resources([
(schema_path.name, schema_resource),
(schema_uri, schema_resource)
])

for cls in vrs_js:
vrs_validator[cls] = Draft202012Validator(vrs_js[cls], registry=vrs_js_registry)
for cls in js_def:
validator[cls] = Draft202012Validator(js_def[cls], registry=js_registry)
6 changes: 3 additions & 3 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jsonschema as js
from ga4gh.gks.metaschema.tools.source_proc import YamlSchemaProcessor

from config import vrs_source_path, vrs_validator
from config import vrs_source_path, validator

# Is the YAML parseable?
p = YamlSchemaProcessor(vrs_source_path)
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_simple_sequence_location():
'end': [None, 150],
'type': 'SequenceLocation'
}
vrs_validator['SequenceLocation'].validate(sl)
validator['SequenceLocation'].validate(sl)

a = {
'location': sl,
Expand All @@ -49,4 +49,4 @@ def test_simple_sequence_location():
},
'type': 'Allele'
}
vrs_validator['Allele'].validate(a)
validator['Allele'].validate(a)
20 changes: 6 additions & 14 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
from config import test_dir, examples_dir
from config import test_path, examples_path
import yaml
from config import vrs_validator


def get_validator(schema_file, schema_class):
validator = globals()[f'{schema_file}_validator'][schema_class]
return validator
from config import validator


def test_examples():
with open(test_dir / 'test_definitions.yaml') as def_file:
with open(test_path / 'test_definitions.yaml') as def_file:
test_spec = yaml.safe_load(def_file)
for test in test_spec['tests']:
with open(examples_dir / test['test_file']) as datafile:
with open(examples_path / test['test_file']) as datafile:
data = yaml.safe_load(datafile)
validator = get_validator(
test['schema'],
test['definition']
)
class_validator = validator[test['definition']]
try:
assert validator.validate(data) is None
assert class_validator.validate(data) is None
except AssertionError as e:
raise AssertionError(f"AssertionError in {test['test_file']}: {e}")

0 comments on commit 3ba7ce1

Please sign in to comment.