@@ -130,24 +130,27 @@ async def test_create_creates_parents(store: Store, zarr_format: ZarrFormat) ->
130
130
assert g .attrs == {}
131
131
132
132
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 :
134
139
"""
135
- Test basic properties of groups
140
+ Test that the path, name, and basename attributes of a group and its subgroups are consistent
136
141
"""
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
141
146
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 ]
151
154
152
155
153
156
@pytest .mark .parametrize ("consolidated_metadata" , [True , False ])
@@ -623,11 +626,13 @@ async def test_group_update_attributes_async(store: Store, zarr_format: ZarrForm
623
626
624
627
625
628
@pytest .mark .parametrize ("method" , ["create_array" , "array" ])
629
+ @pytest .mark .parametrize ("name" , ["a" , "/a" ])
626
630
def test_group_create_array (
627
631
store : Store ,
628
632
zarr_format : ZarrFormat ,
629
633
overwrite : bool ,
630
634
method : Literal ["create_array" , "array" ],
635
+ name : str ,
631
636
) -> None :
632
637
"""
633
638
Test `Group.from_store`
@@ -638,23 +643,26 @@ def test_group_create_array(
638
643
data = np .arange (np .prod (shape )).reshape (shape ).astype (dtype )
639
644
640
645
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 )
642
647
array [:] = data
643
648
elif method == "array" :
644
649
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 )
646
651
else :
647
652
raise AssertionError
648
653
649
654
if not overwrite :
650
655
if method == "create_array" :
651
656
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 )
653
658
a [:] = data
654
659
elif method == "array" :
655
660
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 )
657
662
a [:] = data
663
+
664
+ assert array .path == normalize_path (name )
665
+ assert array .name == "/" + array .path
658
666
assert array .shape == shape
659
667
assert array .dtype == np .dtype (dtype )
660
668
assert np .array_equal (array [:], data )
@@ -945,20 +953,23 @@ async def test_asyncgroup_delitem(store: Store, zarr_format: ZarrFormat) -> None
945
953
raise AssertionError
946
954
947
955
956
+ @pytest .mark .parametrize ("name" , ["a" , "/a" ])
948
957
async def test_asyncgroup_create_group (
949
958
store : Store ,
959
+ name : str ,
950
960
zarr_format : ZarrFormat ,
951
961
) -> None :
952
962
agroup = await AsyncGroup .from_store (store = store , zarr_format = zarr_format )
953
- sub_node_path = "sub_group"
954
963
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
962
973
963
974
964
975
async def test_asyncgroup_create_array (
0 commit comments