2424from zarr .errors import ContainsArrayError , ContainsGroupError
2525from zarr .storage import LocalStore , MemoryStore , StorePath , ZipStore
2626from zarr .storage ._common import make_store_path
27+ from zarr .storage ._utils import normalize_path
2728from zarr .testing .store import LatencyStore
2829
2930from .conftest import parse_store
@@ -111,24 +112,27 @@ async def test_create_creates_parents(store: Store, zarr_format: ZarrFormat) ->
111112 assert g .attrs == {}
112113
113114
114- def test_group_name_properties (store : Store , zarr_format : ZarrFormat ) -> None :
115+ @pytest .mark .parametrize ("store" , ["memory" ], indirect = True )
116+ @pytest .mark .parametrize ("root_name" , ["" , "/" , "a" , "/a" ])
117+ @pytest .mark .parametrize ("branch_name" , ["foo" , "/foo" , "foo/bar" , "/foo/bar" ])
118+ def test_group_name_properties (
119+ store : Store , zarr_format : ZarrFormat , root_name : str , branch_name : str
120+ ) -> None :
115121 """
116- Test basic properties of groups
122+ Test that the path, name, and basename attributes of a group and its subgroups are consistent
117123 """
118- root = Group .from_store (store = store , zarr_format = zarr_format )
119- assert root .path == ""
120- assert root .name == "/"
121- assert root .basename == ""
122-
123- foo = root .create_group ("foo" )
124- assert foo .path == "foo"
125- assert foo .name == "/foo"
126- assert foo .basename == "foo"
127-
128- bar = root .create_group ("foo/bar" )
129- assert bar .path == "foo/bar"
130- assert bar .name == "/foo/bar"
131- assert bar .basename == "bar"
124+ root = Group .from_store (store = StorePath (store = store , path = root_name ), zarr_format = zarr_format )
125+ assert root .path == normalize_path (root_name )
126+ assert root .name == "/" + root .path
127+ assert root .basename == root .path
128+
129+ branch = root .create_group (branch_name )
130+ if root .path == "" :
131+ assert branch .path == normalize_path (branch_name )
132+ else :
133+ assert branch .path == "/" .join ([root .path , normalize_path (branch_name )])
134+ assert branch .name == "/" + branch .path
135+ assert branch .basename == branch_name .split ("/" )[- 1 ]
132136
133137
134138@pytest .mark .parametrize ("consolidated_metadata" , [True , False ])
@@ -601,11 +605,13 @@ async def test_group_update_attributes_async(store: Store, zarr_format: ZarrForm
601605
602606
603607@pytest .mark .parametrize ("method" , ["create_array" , "array" ])
608+ @pytest .mark .parametrize ("name" , ["a" , "/a" ])
604609def test_group_create_array (
605610 store : Store ,
606611 zarr_format : ZarrFormat ,
607612 overwrite : bool ,
608613 method : Literal ["create_array" , "array" ],
614+ name : str ,
609615) -> None :
610616 """
611617 Test `Group.from_store`
@@ -616,23 +622,26 @@ def test_group_create_array(
616622 data = np .arange (np .prod (shape )).reshape (shape ).astype (dtype )
617623
618624 if method == "create_array" :
619- array = group .create_array (name = "array" , shape = shape , dtype = dtype )
625+ array = group .create_array (name = name , shape = shape , dtype = dtype )
620626 array [:] = data
621627 elif method == "array" :
622628 with pytest .warns (DeprecationWarning ):
623- array = group .array (name = "array" , data = data , shape = shape , dtype = dtype )
629+ array = group .array (name = name , data = data , shape = shape , dtype = dtype )
624630 else :
625631 raise AssertionError
626632
627633 if not overwrite :
628634 if method == "create_array" :
629635 with pytest .raises (ContainsArrayError ):
630- a = group .create_array (name = "array" , shape = shape , dtype = dtype )
636+ a = group .create_array (name = name , shape = shape , dtype = dtype )
631637 a [:] = data
632638 elif method == "array" :
633639 with pytest .raises (ContainsArrayError ), pytest .warns (DeprecationWarning ):
634- a = group .array (name = "array" , shape = shape , dtype = dtype )
640+ a = group .array (name = name , shape = shape , dtype = dtype )
635641 a [:] = data
642+
643+ assert array .path == normalize_path (name )
644+ assert array .name == "/" + normalize_path (name )
636645 assert array .shape == shape
637646 assert array .dtype == np .dtype (dtype )
638647 assert np .array_equal (array [:], data )
0 commit comments