|
51 | 51 |
|
52 | 52 | if TYPE_CHECKING: |
53 | 53 | from zarr.core.array_spec import ArrayConfigLike |
54 | | - from zarr.core.metadata.v2 import ArrayV2Metadata |
| 54 | +from zarr.core.metadata.v2 import ArrayV2Metadata |
55 | 55 |
|
56 | 56 |
|
57 | 57 | @pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"]) |
@@ -325,7 +325,7 @@ def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) -> |
325 | 325 |
|
326 | 326 | @pytest.mark.parametrize("store", ["memory"], indirect=True) |
327 | 327 | @pytest.mark.parametrize("zarr_format", [2, 3, "invalid"]) |
328 | | -def test_storage_transformers(store: MemoryStore, zarr_format: ZarrFormat) -> None: |
| 328 | +def test_storage_transformers(store: MemoryStore, zarr_format: ZarrFormat | str) -> None: |
329 | 329 | """ |
330 | 330 | Test that providing an actual storage transformer produces a warning and otherwise passes through |
331 | 331 | """ |
@@ -1131,6 +1131,40 @@ async def test_v3_chunk_encoding( |
1131 | 1131 | assert arr.filters == filters_expected |
1132 | 1132 | assert arr.compressors == compressors_expected |
1133 | 1133 |
|
| 1134 | + @staticmethod |
| 1135 | + @pytest.mark.parametrize("name", ["v2", "default", "invalid"]) |
| 1136 | + @pytest.mark.parametrize("separator", [".", "/"]) |
| 1137 | + async def test_chunk_key_encoding( |
| 1138 | + name: str, separator: str, zarr_format: ZarrFormat, store: MemoryStore |
| 1139 | + ) -> None: |
| 1140 | + chunk_key_encoding = {"name": name, "separator": separator} |
| 1141 | + error_msg = "" |
| 1142 | + if name == "invalid": |
| 1143 | + error_msg = "Unknown chunk key encoding." |
| 1144 | + if zarr_format == 2 and name == "default": |
| 1145 | + error_msg = "Invalid chunk key encoding. For Zarr format 2 arrays, the `name` field of the chunk key encoding must be 'v2'." |
| 1146 | + if error_msg: |
| 1147 | + with pytest.raises(ValueError, match=re.escape(error_msg)): |
| 1148 | + arr = await create_array( |
| 1149 | + store=store, |
| 1150 | + dtype="uint8", |
| 1151 | + shape=(10,), |
| 1152 | + chunks=(1,), |
| 1153 | + zarr_format=zarr_format, |
| 1154 | + chunk_key_encoding=chunk_key_encoding, |
| 1155 | + ) |
| 1156 | + else: |
| 1157 | + arr = await create_array( |
| 1158 | + store=store, |
| 1159 | + dtype="uint8", |
| 1160 | + shape=(10,), |
| 1161 | + chunks=(1,), |
| 1162 | + zarr_format=zarr_format, |
| 1163 | + chunk_key_encoding=chunk_key_encoding, |
| 1164 | + ) |
| 1165 | + if isinstance(arr.metadata, ArrayV2Metadata): |
| 1166 | + assert arr.metadata.dimension_separator == separator |
| 1167 | + |
1134 | 1168 | @staticmethod |
1135 | 1169 | @pytest.mark.parametrize("dtype", ["uint8", "float32", "str"]) |
1136 | 1170 | @pytest.mark.parametrize( |
|
0 commit comments