-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |