Skip to content

Commit 095a052

Browse files
committed
add tests for from_zarr classmethod
1 parent 43ede05 commit 095a052

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/test_core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
import zarr
44
from zarr.errors import ContainsGroupError
5-
from typing import Any, Literal, TypedDict
5+
from typing import Any, Literal, TypedDict, Union
66
import numcodecs
77
from pydantic_zarr.core import ArraySpec, GroupSpec, to_zarr, from_zarr
88
import numpy as np
@@ -150,12 +150,14 @@ class SubGroupAttrs(TypedDict):
150150
a: str
151151
b: float
152152

153+
SubGroup = GroupSpec[SubGroupAttrs, Any]
154+
153155
class ArrayAttrs(TypedDict):
154156
scale: list[float]
155157

156158
store = zarr.MemoryStore()
157159

158-
spec = GroupSpec(
160+
spec = GroupSpec[RootAttrs, Union[ArraySpec, SubGroup]](
159161
attrs=RootAttrs(foo=10, bar=[0, 1, 2]),
160162
members={
161163
"s0": ArraySpec(
@@ -178,7 +180,7 @@ class ArrayAttrs(TypedDict):
178180
dimension_separator=dimension_separator,
179181
attrs=ArrayAttrs(scale=[2.0]),
180182
),
181-
"subgroup": GroupSpec(attrs=SubGroupAttrs(a="foo", b=1.0)),
183+
"subgroup": SubGroup(attrs=SubGroupAttrs(a="foo", b=1.0)),
182184
},
183185
)
184186
# materialize a zarr group, based on the spec
@@ -195,6 +197,11 @@ class ArrayAttrs(TypedDict):
195197
group2 = to_zarr(spec, store, "/group_a", overwrite=True)
196198
assert group2 == group
197199

200+
# again with class methods
201+
group3 = spec.to_zarr(store, "/group_b")
202+
observed = spec.from_zarr(group3)
203+
assert observed == spec
204+
198205

199206
def test_shape_chunks():
200207
for a, b in zip(range(1, 5), range(2, 6)):

0 commit comments

Comments
 (0)