Skip to content

Commit

Permalink
test: add ndarray type test
Browse files Browse the repository at this point in the history
  • Loading branch information
ketozhang committed Jun 28, 2024
1 parent 46cb987 commit 4de4c9b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/patterns/ndarray_type_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import asdf
import numpy as np
from asdf.extension import Extension

from asdf_pydantic import AsdfPydanticConverter, AsdfPydanticModel


class Data(AsdfPydanticModel):
_tag = "asdf://asdf-pydantic/examples/tags/data-1.0.0"
array: np.ndarray


def setup_module():
AsdfPydanticConverter.add_models(Data)

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

converters = [AsdfPydanticConverter()] # type: ignore
tags = [*AsdfPydanticConverter().tags] # type: ignore

asdf.get_config().add_extension(TestExtension())


def test_can_write_with_subclass_model(tmp_path):
data = Data(array=np.array([1, 2, 3]))

af = asdf.AsdfFile({"data": data})
af.write_to(tmp_path / "test.asdf")

with asdf.open(tmp_path / "test.asdf", lazy_load=False) as af:
assert isinstance(af["data"], Data)

0 comments on commit 4de4c9b

Please sign in to comment.