Skip to content

Commit c63a90e

Browse files
committed
test_chunk_key_encoding
1 parent 39cff00 commit c63a90e

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

tests/test_array.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
if TYPE_CHECKING:
5353
from zarr.core.array_spec import ArrayConfigLike
54-
from zarr.core.metadata.v2 import ArrayV2Metadata
54+
from zarr.core.metadata.v2 import ArrayV2Metadata
5555

5656

5757
@pytest.mark.parametrize("store", ["local", "memory", "zip"], indirect=["store"])
@@ -325,7 +325,7 @@ def test_serializable_sync_array(store: LocalStore, zarr_format: ZarrFormat) ->
325325

326326
@pytest.mark.parametrize("store", ["memory"], indirect=True)
327327
@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:
329329
"""
330330
Test that providing an actual storage transformer produces a warning and otherwise passes through
331331
"""
@@ -1131,6 +1131,40 @@ async def test_v3_chunk_encoding(
11311131
assert arr.filters == filters_expected
11321132
assert arr.compressors == compressors_expected
11331133

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+
11341168
@staticmethod
11351169
@pytest.mark.parametrize("dtype", ["uint8", "float32", "str"])
11361170
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)