|
5 | 5 |
|
6 | 6 | import zarr |
7 | 7 | from zarr.abc.store import Store |
8 | | -from zarr.codecs import BytesCodec |
| 8 | +from zarr.codecs import BytesCodec, Endian |
9 | 9 | from zarr.storage import StorePath |
10 | 10 |
|
11 | 11 | from .test_codecs import _AsyncArrayProxy |
@@ -76,3 +76,29 @@ def test_to_dict(endian: str, expected: dict[str, Any]) -> None: |
76 | 76 | actual = codec.to_dict() |
77 | 77 |
|
78 | 78 | 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