Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Jul 17, 2024
1 parent faedc8a commit 51874b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ga4gh/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .pydantic import (
is_pydantic_instance, is_curie_type, pydantic_copy
)
from .domain_models import CommonDomainType
from . import entity_models, domain_models

__all__ = [
Expand All @@ -36,6 +37,7 @@
"is_pydantic_instance",
"is_curie_type",
"pydantic_copy",
"CommonDomainType",
"entity_models",
"domain_models"
]
Expand Down
2 changes: 2 additions & 0 deletions src/ga4gh/vrs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

from .normalize import normalize
from .enderef import vrs_deref, vrs_enref
from .models import VrsType
from . import models

__all__ = [
"normalize",
"vrs_deref",
"vrs_enref",
"VrsType",
"models"
]

Expand Down
24 changes: 22 additions & 2 deletions tests/validation/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import os

from pydantic import ValidationError
import pytest
import yaml

from ga4gh.core import ga4gh_serialize, ga4gh_digest, ga4gh_identify, PrevVrsVersion, entity_models
from ga4gh.vrs import models
from ga4gh.core import ga4gh_serialize, ga4gh_digest, ga4gh_identify, PrevVrsVersion, entity_models, CommonDomainType, domain_models
from ga4gh.vrs import models, VrsType

def ga4gh_1_3_identify(*args, **kwargs):
kwargs['as_version'] = PrevVrsVersion.V1_3
Expand Down Expand Up @@ -96,3 +97,22 @@ def test_prev_vrs_version():

with pytest.raises(ValueError, match="Only `LiteralSequenceExpression` and `ReferenceLengthExpression` are supported for previous versions of VRS"):
ga4gh_func(allele_le, as_version=PrevVrsVersion.V1_3)


def test_valid_types():
"""Ensure that type enums values correct. Values should correspond to class"""
for gks_models, gks_type in [(models, VrsType), (domain_models, CommonDomainType)]:
for attr, value in gks_type.__dict__.items():
if not attr.startswith("__"):
if hasattr(gks_models, value):
gks_class = getattr(gks_models, value)
try:
assert gks_class(type=value)
except ValidationError as e:
found_type_mismatch = False
for error in e.errors():
if error["loc"] == ("type",):
found_type_mismatch = True
assert not found_type_mismatch, f"Found mismatch in type literal: {value} vs {error['ctx']['expected']}"
else:
assert False, f"{str(gks_models)} class not found: {value}"

0 comments on commit 51874b9

Please sign in to comment.