@@ -467,6 +467,25 @@ 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+ await g .create_array (name = "b" , shape = (1 ,), dtype = "float32" )
479+ await g .create_array (name = "d" , shape = (1 ,), dtype = "float32" )
480+ await g .create_array (name = "a" , shape = (1 ,), dtype = "float32" )
481+ await g .create_array (name = "c" , shape = (1 ,), dtype = "float32" )
482+
483+ # Consolidate metadata and re-open store
484+ await zarr .api .asynchronous .consolidate_metadata (memory_store )
485+ g2 = await zarr .api .asynchronous .open_group (store = memory_store )
486+
487+ assert list (g2 .metadata .consolidated_metadata .metadata ) == ["a" , "b" , "c" , "d" ]
488+
470489 @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
471490 async def test_open_consolidated_raises_async (self , zarr_format : ZarrFormat ):
472491 store = zarr .storage .MemoryStore ()
0 commit comments