Skip to content

Commit 2fa0082

Browse files
dcheriand-v-b
andauthored
Explicitly clear store in hypothesis strategy (#2481)
Co-authored-by: Davis Bennett <[email protected]>
1 parent 846f33b commit 2fa0082

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/zarr/testing/strategies.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from zarr.core.array import Array
1010
from zarr.core.group import Group
11+
from zarr.core.sync import sync
1112
from zarr.storage import MemoryStore, StoreLike
1213

1314
# Copied from Xarray
@@ -42,7 +43,7 @@ def v2_dtypes() -> st.SearchStrategy[np.dtype]:
4243
| npst.complex_number_dtypes(endianness="=")
4344
| npst.byte_string_dtypes(endianness="=")
4445
| npst.unicode_string_dtypes(endianness="=")
45-
| npst.datetime64_dtypes()
46+
| npst.datetime64_dtypes(endianness="=")
4647
# | npst.timedelta64_dtypes()
4748
)
4849

@@ -62,7 +63,10 @@ def v2_dtypes() -> st.SearchStrategy[np.dtype]:
6263
attrs = st.none() | st.dictionaries(_attr_keys, _attr_values)
6364
keys = st.lists(node_names, min_size=1).map("/".join)
6465
paths = st.just("/") | keys
65-
stores = st.builds(MemoryStore, st.just({}), mode=st.just("w"))
66+
# st.builds will only call a new store constructor for different keyword arguments
67+
# i.e. stores.examples() will always return the same object per Store class.
68+
# So we map a clear to reset the store.
69+
stores = st.builds(MemoryStore, st.just({})).map(lambda x: sync(x.clear()))
6670
compressors = st.sampled_from([None, "default"])
6771
zarr_formats: st.SearchStrategy[Literal[2, 3]] = st.sampled_from([2, 3])
6872
array_shapes = npst.array_shapes(max_dims=4, min_side=0)

0 commit comments

Comments
 (0)