1
1
from __future__ import annotations
2
2
3
+ import contextlib
3
4
import pickle
5
+ import warnings
4
6
from typing import TYPE_CHECKING , Any , Literal , cast
5
7
6
8
import numpy as np
@@ -177,22 +179,33 @@ def test_group_members(store: Store, zarr_format: ZarrFormat, consolidated_metad
177
179
)
178
180
)
179
181
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
+ )
180
186
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 ()
182
192
group = zarr .open_consolidated (store = store , zarr_format = zarr_format )
183
193
184
- members_observed = group .members ()
194
+ with warn_context :
195
+ members_observed = group .members ()
185
196
# members are not guaranteed to be ordered, so sort before comparing
186
197
assert sorted (dict (members_observed )) == sorted (members_expected )
187
198
188
199
# partial
189
- members_observed = group .members (max_depth = 1 )
200
+ with warn_context :
201
+ members_observed = group .members (max_depth = 1 )
190
202
members_expected ["subgroup/subsubgroup" ] = subsubgroup
191
203
# members are not guaranteed to be ordered, so sort before comparing
192
204
assert sorted (dict (members_observed )) == sorted (members_expected )
193
205
194
206
# total
195
- members_observed = group .members (max_depth = None )
207
+ with warn_context :
208
+ members_observed = group .members (max_depth = None )
196
209
members_expected ["subgroup/subsubgroup/subsubsubgroup" ] = subsubsubgroup
197
210
# members are not guaranteed to be ordered, so sort before comparing
198
211
assert sorted (dict (members_observed )) == sorted (members_expected )
@@ -1091,8 +1104,8 @@ async def test_require_array(store: Store, zarr_format: ZarrFormat) -> None:
1091
1104
1092
1105
1093
1106
@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 )
1096
1109
a = group .create_group (name = "a" )
1097
1110
a .create_array ("array" , shape = (1 ,))
1098
1111
b = a .create_group (name = "b" )
@@ -1108,6 +1121,12 @@ def test_members_name(store: Store, consolidate: bool):
1108
1121
expected = ["/a" , "/a/array" , "/a/b" , "/a/b/array" ]
1109
1122
assert paths == expected
1110
1123
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
+
1111
1130
1112
1131
async def test_open_mutable_mapping ():
1113
1132
group = await zarr .api .asynchronous .open_group (store = {}, mode = "w" )
0 commit comments