Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
"""Provide utilities for test cases."""

from enum import Enum
from pathlib import Path

SUBMODULES_DIR = Path(__file__).parents[1] / "submodules" / "va_spec"


class VaSpecSchema(str, Enum):
"""Enum for VA-Spec schema"""

AAC_2017 = "aac-2017"
ACMG_2015 = "acmg-2015"
BASE = "base"
CCV_2022 = "ccv-2022"


def get_va_spec_schema(label: str) -> str | None:
"""Get VA-Spec schema given label

:param label: Label
:return: VA-Spec label
"""
if label.endswith(VaSpecSchema.AAC_2017):
schema = VaSpecSchema.AAC_2017
elif label.endswith(VaSpecSchema.ACMG_2015):
schema = VaSpecSchema.ACMG_2015
elif label.endswith(VaSpecSchema.BASE):
schema = VaSpecSchema.BASE
elif label.endswith(VaSpecSchema.CCV_2022):
schema = VaSpecSchema.CCV_2022
else:
schema = None
return schema
42 changes: 42 additions & 0 deletions tests/validation/test_va_spec_fixtures_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Ensure that VA-Spec test fixtures validate against Pydantic models"""

import yaml
from ga4gh.va_spec import aac_2017, acmg_2015, base, ccv_2022

from tests.conftest import SUBMODULES_DIR, VaSpecSchema, get_va_spec_schema

VA_SPEC_TESTS_DIR = SUBMODULES_DIR / "tests"


with (VA_SPEC_TESTS_DIR / "test_definitions.yaml").open() as f:
data = yaml.load(f, Loader=yaml.SafeLoader)
test_definitions = data["tests"]

SCHEMA_TO_PYDANTIC_MODULE = {
VaSpecSchema.AAC_2017: aac_2017,
VaSpecSchema.ACMG_2015: acmg_2015,
VaSpecSchema.CCV_2022: ccv_2022,
VaSpecSchema.BASE: base,
}
VA_SPEC_TEST_DEFINITIONS = {schema: [] for schema in VaSpecSchema}


for test_def in test_definitions:
if test_def["namespace"].startswith("va-spec."):
schema = get_va_spec_schema(test_def["namespace"].split("va-spec.")[-1])
VA_SPEC_TEST_DEFINITIONS[schema].append(test_def)


def test_va_spec_fixtures():
"""Test that VA-Spec test fixtures validate against Pydantic models"""
for va_spec_schema, schema_test_defs in VA_SPEC_TEST_DEFINITIONS.items():
pydantic_module = SCHEMA_TO_PYDANTIC_MODULE[va_spec_schema]

for schema_test_def in schema_test_defs:
with (
VA_SPEC_TESTS_DIR / "fixtures" / schema_test_def["test_file"]
).open() as f:
test_fixture_dict = yaml.load(f, Loader=yaml.SafeLoader)
va_spec_class = schema_test_def["definition"]
pydantic_model = getattr(pydantic_module, va_spec_class)
assert pydantic_model(**test_fixture_dict)
27 changes: 7 additions & 20 deletions tests/validation/test_va_spec_schema.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
"""Test that VA-Spec Python Pydantic models match corresponding JSON schemas"""

import json
from enum import Enum
from pathlib import Path

import pytest
from ga4gh.va_spec import aac_2017, acmg_2015, base, ccv_2022
from pydantic import BaseModel

from tests.conftest import SUBMODULES_DIR
from tests.conftest import (
SUBMODULES_DIR,
VaSpecSchema,
get_va_spec_schema,
)

VA_SCHEMA_DIR = SUBMODULES_DIR / "schema" / "va-spec"


class VaSpecSchema(str, Enum):
"""Enum for VA-Spec schema"""

AAC_2017 = "aac-2017"
ACMG_2015 = "acmg-2015"
BASE = "base"
CCV_2022 = "ccv-2022"


class VaSpecSchemaMapping(BaseModel):
"""Model for representing VA-Spec Schema concrete classes, primitives, and schema"""

Expand Down Expand Up @@ -59,15 +53,8 @@ def _update_va_spec_schema_mapping(
# Get core + profiles classes
for child in VA_SCHEMA_DIR.iterdir():
child_str = str(child)
if child_str.endswith(VaSpecSchema.AAC_2017):
mapping_key = VaSpecSchema.AAC_2017
elif child_str.endswith(VaSpecSchema.ACMG_2015):
mapping_key = VaSpecSchema.ACMG_2015
elif child_str.endswith(VaSpecSchema.BASE):
mapping_key = VaSpecSchema.BASE
elif child_str.endswith(VaSpecSchema.CCV_2022):
mapping_key = VaSpecSchema.CCV_2022
else:
mapping_key = get_va_spec_schema(child_str)
if not mapping_key:
continue

mapping = VA_SPEC_SCHEMA_MAPPING[mapping_key]
Expand Down