Skip to content

Commit e2b1504

Browse files
committed
Add test to verify order of consolidated metadata
1 parent 383174b commit e2b1504

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_metadata/test_consolidated.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,29 @@ def test_to_dict_empty(self):
467467
}
468468
assert result == expected
469469

470+
@pytest.mark.parametrize("zarr_format", [2, 3])
471+
async def test_to_dict_order(
472+
self, memory_store: zarr.storage.MemoryStore, zarr_format: ZarrFormat
473+
) -> None:
474+
with zarr.config.set(default_zarr_format=zarr_format):
475+
g = await group(store=memory_store)
476+
477+
# Create groups in non-lexicographix order
478+
dtype = "float32"
479+
await g.create_array(name="b", shape=(1,), dtype=dtype)
480+
child = await g.create_group("c", attributes={"key": "child"})
481+
await g.create_array(name="a", shape=(1,), dtype=dtype)
482+
483+
await child.create_array("e", shape=(1,), dtype=dtype)
484+
await child.create_array("d", shape=(1,), dtype=dtype)
485+
486+
# Consolidate metadata and re-open store
487+
await zarr.api.asynchronous.consolidate_metadata(memory_store)
488+
g2 = await zarr.api.asynchronous.open_group(store=memory_store)
489+
490+
assert list(g2.metadata.consolidated_metadata.metadata) == ["a", "b", "c"]
491+
assert list(g2.metadata.consolidated_metadata.flattened_metadata) == ["a", "b", "c", "c/d", "c/e"]
492+
470493
@pytest.mark.parametrize("zarr_format", [2, 3])
471494
async def test_open_consolidated_raises_async(self, zarr_format: ZarrFormat):
472495
store = zarr.storage.MemoryStore()

0 commit comments

Comments
 (0)