11from __future__ import annotations
22
3+ import contextlib
34import pickle
5+ import warnings
46from typing import TYPE_CHECKING , Any , Literal , cast
57
68import numpy as np
@@ -177,22 +179,33 @@ def test_group_members(store: Store, zarr_format: ZarrFormat, consolidated_metad
177179 )
178180 )
179181
182+ # this warning shows up when extra objects show up in the hierarchy
183+ warn_context = pytest .warns (
184+ UserWarning , match = r"Object at .* is not recognized as a component of a Zarr hierarchy."
185+ )
180186 if consolidated_metadata :
181- zarr .consolidate_metadata (store = store , zarr_format = zarr_format )
187+ with warn_context :
188+ zarr .consolidate_metadata (store = store , zarr_format = zarr_format )
189+ # now that we've consolidated the store, we shouldn't get the warnings from the unrecognized objects anymore
190+ # we use a nullcontext to handle these cases
191+ warn_context = contextlib .nullcontext ()
182192 group = zarr .open_consolidated (store = store , zarr_format = zarr_format )
183193
184- members_observed = group .members ()
194+ with warn_context :
195+ members_observed = group .members ()
185196 # members are not guaranteed to be ordered, so sort before comparing
186197 assert sorted (dict (members_observed )) == sorted (members_expected )
187198
188199 # partial
189- members_observed = group .members (max_depth = 1 )
200+ with warn_context :
201+ members_observed = group .members (max_depth = 1 )
190202 members_expected ["subgroup/subsubgroup" ] = subsubgroup
191203 # members are not guaranteed to be ordered, so sort before comparing
192204 assert sorted (dict (members_observed )) == sorted (members_expected )
193205
194206 # total
195- members_observed = group .members (max_depth = None )
207+ with warn_context :
208+ members_observed = group .members (max_depth = None )
196209 members_expected ["subgroup/subsubgroup/subsubsubgroup" ] = subsubsubgroup
197210 # members are not guaranteed to be ordered, so sort before comparing
198211 assert sorted (dict (members_observed )) == sorted (members_expected )
@@ -1137,8 +1150,8 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None:
11371150
11381151
11391152@pytest .mark .parametrize ("consolidate" , [True , False ])
1140- def test_members_name (store : Store , consolidate : bool ):
1141- group = Group .from_store (store = store )
1153+ async def test_members_name (store : Store , consolidate : bool , zarr_format : ZarrFormat ):
1154+ group = Group .from_store (store = store , zarr_format = zarr_format )
11421155 a = group .create_group (name = "a" )
11431156 a .create_array ("array" , shape = (1 ,))
11441157 b = a .create_group (name = "b" )
@@ -1154,6 +1167,12 @@ def test_members_name(store: Store, consolidate: bool):
11541167 expected = ["/a" , "/a/array" , "/a/b" , "/a/b/array" ]
11551168 assert paths == expected
11561169
1170+ # regression test for https://github.com/zarr-developers/zarr-python/pull/2356
1171+ g = zarr .open_group (store , use_consolidated = False )
1172+ with warnings .catch_warnings ():
1173+ warnings .simplefilter ("error" )
1174+ assert list (g )
1175+
11571176
11581177async def test_open_mutable_mapping ():
11591178 group = await zarr .api .asynchronous .open_group (store = {}, mode = "w" )
0 commit comments