Skip to content

Commit f957c13

Browse files
committed
Add test to verify order of consolidated metadata
1 parent 83833bd commit f957c13

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_metadata/test_consolidated.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,35 @@ 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) == [
492+
"a",
493+
"b",
494+
"c",
495+
"c/d",
496+
"c/e",
497+
]
498+
470499
@pytest.mark.parametrize("zarr_format", [2, 3])
471500
async def test_open_consolidated_raises_async(self, zarr_format: ZarrFormat):
472501
store = zarr.storage.MemoryStore()

0 commit comments

Comments
 (0)