Skip to content

Commit

Permalink
test: Update how asdf extension is created in schema_validation_test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ketozhang committed Jun 17, 2024
1 parent 6edbd7d commit 12f56c1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions tests/schema_validation_test.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
from tempfile import NamedTemporaryFile

import asdf
import jsonschema
import pydantic
import pytest
import yaml
from asdf.extension import Extension
from asdf_pydantic import AsdfPydanticConverter

from asdf_pydantic.examples.extensions import ExampleExtension
from asdf_pydantic.examples.shapes import AsdfRectangle
from asdf_pydantic.examples.tree import AsdfNode


class TestExtension(ExampleExtension):
tags = [ # type: ignore
TagDefinition(
AsdfRectangle._tag,
schema_uris="asdf://asdf-pydantic/shapes/schemas/rectangle-1.0.0",
)
]
def setup_module():
AsdfPydanticConverter.add_models(AsdfRectangle)

class TestExtension(Extension):
extension_uri = "asdf://asdf-pydantic/examples/extensions/test-1.0.0" # type: ignore

def setup_module():
asdf.get_config().add_extension(TestExtension())
tags = [*AsdfPydanticConverter().tags] # type: ignore
converters = [AsdfPydanticConverter()] # type: ignore

# HACK: The schema URI should be referenced from `AsdfRectangle._schema`.
# Then there should be a way to automatically add the schema to ASDF
# resources perhaps during AsdfPydanticConverter.add_models(). Further
# abstracting can be done later, perhaps defining a
# AsdfPydanticExtension.
asdf.get_config().add_resource_mapping(
{
"asdf://asdf-pydantic/shapes/schemas/rectangle-1.0.0": (
AsdfRectangle.schema_asdf().encode("utf-8")
)
}
)
asdf.get_config().add_extension(TestExtension())


def test_schema_exists_and_valid():
Expand Down

0 comments on commit 12f56c1

Please sign in to comment.