|
| 1 | +from codecs import Codec |
1 | 2 | import pickle |
2 | | -from typing import Any |
| 3 | +from typing import Any, Literal |
3 | 4 |
|
4 | 5 | import numpy as np |
5 | 6 | import numpy.typing as npt |
|
16 | 17 | ShardingCodecIndexLocation, |
17 | 18 | TransposeCodec, |
18 | 19 | ) |
| 20 | +from zarr.codecs.bytes import BytesCodec |
| 21 | +from zarr.codecs.crc32c_ import Crc32cCodec |
| 22 | +from zarr.codecs.sharding import ShardingJSON_V2, ShardingJSON_V3 |
19 | 23 | from zarr.core.buffer import NDArrayLike, default_buffer_prototype |
20 | 24 | from zarr.storage import StorePath |
21 | 25 |
|
22 | 26 | from ..conftest import ArrayRequest |
23 | 27 | from .test_codecs import _AsyncArrayProxy, order_from_dim |
24 | 28 |
|
25 | 29 |
|
| 30 | +@pytest.mark.parametrize("index_location", ["start", "end"]) |
| 31 | +@pytest.mark.parametrize("chunk_shape", [(32, 32), (64, 64)]) |
| 32 | +@pytest.mark.parametrize('codecs', [(BytesCodec(),)]) |
| 33 | +@pytest.mark.parametrize('index_codecs', [(Crc32cCodec(),)]) |
| 34 | +def test_sharding_codec_to_json(index_location: Literal["start", "end"], chunk_shape: tuple[int, ...], codecs: tuple[Codec, ...], index_codecs: tuple[Codec, ...]) -> None: |
| 35 | + codec = ShardingCodec(chunk_shape=chunk_shape, codecs=codecs, index_location=index_location, index_codecs=index_codecs) |
| 36 | + expected_v2: ShardingJSON_V2 = { |
| 37 | + "id": "sharding_indexed", |
| 38 | + "chunk_shape": chunk_shape, |
| 39 | + "codecs": tuple(c.to_json(zarr_format=2) for c in codecs), |
| 40 | + "index_codecs": tuple(c.to_json(zarr_format=2) for c in index_codecs), |
| 41 | + "index_location": index_location, |
| 42 | + } |
| 43 | + expected_v3: ShardingJSON_V3 = { |
| 44 | + "name": "sharding_indexed", |
| 45 | + "configuration": { |
| 46 | + "chunk_shape": chunk_shape, |
| 47 | + "codecs": tuple(c.to_json(zarr_format=3) for c in codecs), |
| 48 | + "index_codecs": tuple(c.to_json(zarr_format=3) for c in index_codecs), |
| 49 | + "index_location": index_location, |
| 50 | + }, |
| 51 | + } |
| 52 | + assert codec.to_json(zarr_format=2) == expected_v2 |
| 53 | + assert codec.to_json(zarr_format=3) == expected_v3 |
| 54 | + |
| 55 | + |
26 | 56 | @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) |
27 | 57 | @pytest.mark.parametrize("index_location", ["start", "end"]) |
28 | 58 | @pytest.mark.parametrize( |
|
0 commit comments