Skip to content

Commit cfad862

Browse files
committed
tests for from_dict and roundtripping
1 parent bde404e commit cfad862

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/test_codecs/test_bytes.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import zarr
77
from zarr.abc.store import Store
8-
from zarr.codecs import BytesCodec
8+
from zarr.codecs import BytesCodec, Endian
99
from zarr.storage import StorePath
1010

1111
from .test_codecs import _AsyncArrayProxy
@@ -76,3 +76,29 @@ def test_to_dict(endian: str, expected: dict[str, Any]) -> None:
7676
actual = codec.to_dict()
7777

7878
assert actual == expected
79+
80+
81+
@pytest.mark.parametrize(
82+
("mapping", "expected"),
83+
[
84+
pytest.param(
85+
{"name": "bytes", "configuration": {"endian": "little"}}, Endian.little, id="little"
86+
),
87+
pytest.param({"name": "bytes", "configuration": {"endian": "big"}}, Endian.big, id="big"),
88+
pytest.param({"name": "bytes"}, None, id="missing"),
89+
],
90+
)
91+
def test_from_dict(mapping: dict[str, Any], expected: Endian | None) -> None:
92+
actual = BytesCodec.from_dict(mapping)
93+
94+
assert actual.endian == expected
95+
96+
97+
@pytest.mark.parametrize("endian", ["little", "big", pytest.param(None, id="missing")])
98+
def test_roundtrip(endian: str | None) -> None:
99+
codec = BytesCodec(endian=endian)
100+
101+
encoded = codec.to_dict()
102+
roundtripped = BytesCodec.from_dict(encoded)
103+
104+
assert codec == roundtripped

0 commit comments

Comments
 (0)