@@ -130,24 +130,27 @@ async def test_create_creates_parents(store: Store, zarr_format: ZarrFormat) ->
130130 assert g .attrs == {}
131131
132132
133- def test_group_name_properties (store : Store , zarr_format : ZarrFormat ) -> None :
133+ @pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
134+ @pytest .mark .parametrize ("root_name" , ["" , "/" , "a" , "/a" ])
135+ @pytest .mark .parametrize ("branch_name" , ["foo" , "/foo" , "foo/bar" , "/foo/bar" ])
136+ def test_group_name_properties (
137+ store : Store , zarr_format : ZarrFormat , root_name : str , branch_name : str
138+ ) -> None :
134139 """
135- Test basic properties of groups
140+ Test that the path, name, and basename attributes of a group and its subgroups are consistent
136141 """
137- root = Group .from_store (store = store , zarr_format = zarr_format )
138- assert root .path == ""
139- assert root .name == "/"
140- assert root .basename == ""
142+ root = Group .from_store (store = StorePath ( store = store , path = root_name ) , zarr_format = zarr_format )
143+ assert root .path == normalize_path ( root_name )
144+ assert root .name == "/" + root . path
145+ assert root .basename == root . path
141146
142- foo = root .create_group ("foo" )
143- assert foo .path == "foo"
144- assert foo .name == "/foo"
145- assert foo .basename == "foo"
146-
147- bar = root .create_group ("foo/bar" )
148- assert bar .path == "foo/bar"
149- assert bar .name == "/foo/bar"
150- assert bar .basename == "bar"
147+ branch = root .create_group (branch_name )
148+ if root .path == "" :
149+ assert branch .path == normalize_path (branch_name )
150+ else :
151+ assert branch .path == "/" .join ([root .path , normalize_path (branch_name )])
152+ assert branch .name == "/" + branch .path
153+ assert branch .basename == branch_name .split ("/" )[- 1 ]
151154
152155
153156@pytest .mark .parametrize ("consolidated_metadata" , [True , False ])
@@ -623,11 +626,13 @@ async def test_group_update_attributes_async(store: Store, zarr_format: ZarrForm
623626
624627
625628@pytest .mark .parametrize ("method" , ["create_array" , "array" ])
629+ @pytest .mark .parametrize ("name" , ["a" , "/a" ])
626630def test_group_create_array (
627631 store : Store ,
628632 zarr_format : ZarrFormat ,
629633 overwrite : bool ,
630634 method : Literal ["create_array" , "array" ],
635+ name : str ,
631636) -> None :
632637 """
633638 Test `Group.from_store`
@@ -638,23 +643,26 @@ def test_group_create_array(
638643 data = np .arange (np .prod (shape )).reshape (shape ).astype (dtype )
639644
640645 if method == "create_array" :
641- array = group .create_array (name = "array" , shape = shape , dtype = dtype )
646+ array = group .create_array (name = name , shape = shape , dtype = dtype )
642647 array [:] = data
643648 elif method == "array" :
644649 with pytest .warns (DeprecationWarning ):
645- array = group .array (name = "array" , data = data , shape = shape , dtype = dtype )
650+ array = group .array (name = name , data = data , shape = shape , dtype = dtype )
646651 else :
647652 raise AssertionError
648653
649654 if not overwrite :
650655 if method == "create_array" :
651656 with pytest .raises (ContainsArrayError ):
652- a = group .create_array (name = "array" , shape = shape , dtype = dtype )
657+ a = group .create_array (name = name , shape = shape , dtype = dtype )
653658 a [:] = data
654659 elif method == "array" :
655660 with pytest .raises (ContainsArrayError ), pytest .warns (DeprecationWarning ):
656- a = group .array (name = "array" , shape = shape , dtype = dtype )
661+ a = group .array (name = name , shape = shape , dtype = dtype )
657662 a [:] = data
663+
664+ assert array .path == normalize_path (name )
665+ assert array .name == "/" + array .path
658666 assert array .shape == shape
659667 assert array .dtype == np .dtype (dtype )
660668 assert np .array_equal (array [:], data )
@@ -945,20 +953,23 @@ async def test_asyncgroup_delitem(store: Store, zarr_format: ZarrFormat) -> None
945953 raise AssertionError
946954
947955
956+ @pytest .mark .parametrize ("name" , ["a" , "/a" ])
948957async def test_asyncgroup_create_group (
949958 store : Store ,
959+ name : str ,
950960 zarr_format : ZarrFormat ,
951961) -> None :
952962 agroup = await AsyncGroup .from_store (store = store , zarr_format = zarr_format )
953- sub_node_path = "sub_group"
954963 attributes = {"foo" : 999 }
955- subnode = await agroup .create_group (name = sub_node_path , attributes = attributes )
956-
957- assert isinstance (subnode , AsyncGroup )
958- assert subnode .attrs == attributes
959- assert subnode .store_path .path == sub_node_path
960- assert subnode .store_path .store == store
961- assert subnode .metadata .zarr_format == zarr_format
964+ subgroup = await agroup .create_group (name = name , attributes = attributes )
965+
966+ assert isinstance (subgroup , AsyncGroup )
967+ assert subgroup .path == normalize_path (name )
968+ assert subgroup .name == "/" + subgroup .path
969+ assert subgroup .attrs == attributes
970+ assert subgroup .store_path .path == subgroup .path
971+ assert subgroup .store_path .store == store
972+ assert subgroup .metadata .zarr_format == zarr_format
962973
963974
964975async def test_asyncgroup_create_array (
0 commit comments