Skip to content

Commit

Permalink
feat!: migrate example models to tests/ and remove example extension …
Browse files Browse the repository at this point in the history
…from package

fixes #37
  • Loading branch information
ketozhang committed Nov 17, 2024
1 parent 4970e72 commit c84652f
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
Empty file removed asdf_pydantic/examples/__init__.py
Empty file.
19 changes: 0 additions & 19 deletions asdf_pydantic/examples/extensions.py

This file was deleted.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ Documentation = "https://asdf-pydantic.readthedocs.io"
Issues = "https://github.com/ketozhang/asdf-pydantic/issues"
Source = "https://github.com/ketozhang/asdf-pydantic"

[project.entry-points]
'asdf.extensions' = { asdf_pydantic_extension = 'asdf_pydantic.examples.extensions:get_extensions' }

[tool.hatch.version]
source = "vcs"

Expand Down
2 changes: 1 addition & 1 deletion tests/convert_to_asdf_yaml_tree_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from asdf_pydantic.examples.tree import AsdfTreeNode, Node
from tests.examples.tree import AsdfTreeNode, Node


def test_sanity():
Expand Down
11 changes: 0 additions & 11 deletions tests/entry_point_test.py

This file was deleted.

File renamed without changes.
9 changes: 2 additions & 7 deletions tests/examples/test_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
import yaml
from asdf.extension import Extension

from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel


class AsdfRectangle(AsdfPydanticModel):
_tag = "asdf://asdf-pydantic/examples/tags/rectangle-1.0.0"
width: float
height: float
from asdf_pydantic import AsdfPydanticConverter
from tests.examples.shapes import AsdfRectangle


@pytest.fixture()
Expand Down
File renamed without changes.
35 changes: 33 additions & 2 deletions tests/schema_validation_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tempfile import NamedTemporaryFile
from typing import Annotated

import asdf
import pydantic
Expand All @@ -7,8 +8,9 @@
from asdf.extension import Extension

from asdf_pydantic import AsdfPydanticConverter
from asdf_pydantic.examples.shapes import AsdfRectangle
from asdf_pydantic.examples.tree import AsdfTreeNode
from asdf_pydantic.model import AsdfPydanticModel
from tests.examples.shapes import AsdfRectangle
from tests.examples.tree import AsdfTreeNode


def setup_module():
Expand Down Expand Up @@ -136,3 +138,32 @@ def test_given_child_field_contains_asdf_object_then_schema_has_child_tag():
child_schema = schema["definitions"]["AsdfNode"]["properties"]["child"]

assert {"tag": AsdfTreeNode._tag} in child_schema["anyOf"]


########################################################################################
# AsdfTag
########################################################################################
from asdf_pydantic.schema import AsdfTag # noqa: E402


@pytest.mark.parametrize(
"asdf_tag_str, mode, expected_ref_key",
[
("http://stsci.edu/schemas/asdf/unit/quantity-1.2.0", "auto", "$ref"),
("http://stsci.edu/schemas/asdf/unit/quantity-1.2.0", "ref", "$ref"),
("tag:stsci.edu:asdf/table/table-1.1.0", "auto", "tag"),
("tag:stsci.edu:asdf/table/table-1.1.0", "tag", "tag"),
],
)
def test_tag_mode(asdf_tag_str: str, mode, expected_ref_key):
"""Test that schema correctly has ``$ref:`` or ``tag:`` depending on the
selected mode.
"""
from astropy.table import Table

class TestModel(AsdfPydanticModel):
_tag = "asdf://asdf-pydantic/examples/tags/test-model-1.0.0"
table: Annotated[Table, AsdfTag(asdf_tag_str, mode=mode)]

schema = yaml.safe_load(TestModel.model_asdf_schema())
assert expected_ref_key in schema["properties"]["table"]

0 comments on commit c84652f

Please sign in to comment.