2525 ConsolidatedMetadata ,
2626 GroupMetadata ,
2727 _create_rooted_hierarchy ,
28+ _create_rooted_hierarchy_sync ,
2829 _join_paths ,
2930 _normalize_path_keys ,
3031 _normalize_paths ,
@@ -1648,7 +1649,7 @@ async def test_create_rooted_hierarchy_group(store: Store, zarr_format, path: st
16481649
16491650 nodes_create = root_meta | groups_expected_meta | arrays_expected_meta
16501651
1651- g = await _create_rooted_hierarchy (spath , nodes = nodes_create , overwrite = True )
1652+ g = await _create_rooted_hierarchy (spath , nodes = nodes_create )
16521653 assert g .metadata .attributes == {"path" : root_key }
16531654
16541655 members = await _collect_aiterator (g .members (max_depth = None ))
@@ -1660,6 +1661,48 @@ async def test_create_rooted_hierarchy_group(store: Store, zarr_format, path: st
16601661 assert members_observed_meta == members_expected_meta_relative
16611662
16621663
1664+ # TODO: simplify testing sync versions of async functions.
1665+ @pytest .mark .parametrize ("store" , ["memory" , "local" ], indirect = True )
1666+ @pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
1667+ @pytest .mark .parametrize ("root_key" , ["" , "root" ])
1668+ @pytest .mark .parametrize ("path" , ["" , "foo" ])
1669+ def test_create_rooted_hierarchy_sync_group (store : Store , zarr_format , path : str , root_key : str ):
1670+ """
1671+ Test that the _create_rooted_hierarchy_sync can create a group.
1672+ """
1673+ spath = sync (make_store_path (store , path = path ))
1674+ root_meta = {root_key : GroupMetadata (zarr_format = zarr_format , attributes = {"path" : root_key })}
1675+ group_names = ["a" , "a/b" ]
1676+ array_names = ["a/b/c" , "a/b/d" ]
1677+
1678+ # just to ensure that we don't use the same name twice in tests
1679+ assert set (group_names ) & set (array_names ) == set ()
1680+
1681+ groups_expected_meta = {
1682+ _join_paths ([root_key , node_name ]): GroupMetadata (
1683+ zarr_format = zarr_format , attributes = {"path" : node_name }
1684+ )
1685+ for node_name in group_names
1686+ }
1687+ arrays_expected_meta = {
1688+ _join_paths ([root_key , node_name ]): meta_from_array (np .zeros (4 ), zarr_format = zarr_format )
1689+ for node_name in array_names
1690+ }
1691+
1692+ nodes_create = root_meta | groups_expected_meta | arrays_expected_meta
1693+
1694+ g = _create_rooted_hierarchy_sync (spath , nodes = nodes_create )
1695+ assert g .metadata .attributes == {"path" : root_key }
1696+
1697+ members = g .members (max_depth = None )
1698+ members_observed_meta = {k : v .metadata for k , v in members }
1699+ members_expected_meta_relative = {
1700+ k .removeprefix (root_key ).lstrip ("/" ): v
1701+ for k , v in (groups_expected_meta | arrays_expected_meta ).items ()
1702+ }
1703+ assert members_observed_meta == members_expected_meta_relative
1704+
1705+
16631706@pytest .mark .parametrize ("store" , ["memory" , "local" ], indirect = True )
16641707@pytest .mark .parametrize ("zarr_format" , [2 , 3 ])
16651708@pytest .mark .parametrize ("root_key" , ["" , "root" ])
0 commit comments