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 )
@@ -1091,8 +1104,8 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None:
10911104
10921105
10931106@pytest .mark .parametrize ("consolidate" , [True , False ])
1094- def test_members_name (store : Store , consolidate : bool ):
1095- group = Group .from_store (store = store )
1107+ async def test_members_name (store : Store , consolidate : bool , zarr_format : ZarrFormat ):
1108+ group = Group .from_store (store = store , zarr_format = zarr_format )
10961109 a = group .create_group (name = "a" )
10971110 a .create_array ("array" , shape = (1 ,))
10981111 b = a .create_group (name = "b" )
@@ -1108,6 +1121,12 @@ def test_members_name(store: Store, consolidate: bool):
11081121 expected = ["/a" , "/a/array" , "/a/b" , "/a/b/array" ]
11091122 assert paths == expected
11101123
1124+ # regression test for https://github.com/zarr-developers/zarr-python/pull/2356
1125+ g = zarr .open_group (store , use_consolidated = False )
1126+ with warnings .catch_warnings ():
1127+ warnings .simplefilter ("error" )
1128+ assert list (g )
1129+
11111130
11121131async def test_open_mutable_mapping ():
11131132 group = await zarr .api .asynchronous .open_group (store = {}, mode = "w" )
0 commit comments