diff --git a/src/ga4gh/core/__init__.py b/src/ga4gh/core/__init__.py index 3941f2e..196c20e 100644 --- a/src/ga4gh/core/__init__.py +++ b/src/ga4gh/core/__init__.py @@ -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__ = [ @@ -36,6 +37,7 @@ "is_pydantic_instance", "is_curie_type", "pydantic_copy", + "CommonDomainType", "entity_models", "domain_models" ] diff --git a/src/ga4gh/vrs/__init__.py b/src/ga4gh/vrs/__init__.py index adbec05..997c9a5 100644 --- a/src/ga4gh/vrs/__init__.py +++ b/src/ga4gh/vrs/__init__.py @@ -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" ] diff --git a/tests/validation/test_models.py b/tests/validation/test_models.py index 50c1ec6..e86ebbe 100644 --- a/tests/validation/test_models.py +++ b/tests/validation/test_models.py @@ -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 @@ -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}"