Skip to content

Commit 9bd02c0

Browse files
committed
Use short node names
1 parent 63eb1ea commit 9bd02c0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/zarr/testing/strategies.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
)
3030

3131

32+
@st.composite # type: ignore[misc]
33+
def keys(draw: st.DrawFn, *, max_num_nodes: int | None = None) -> Any:
34+
return draw(st.lists(node_names, min_size=1, max_size=max_num_nodes).map("/".join))
35+
36+
37+
@st.composite # type: ignore[misc]
38+
def paths(draw: st.DrawFn, *, max_num_nodes: int | None = None) -> Any:
39+
return draw(st.just("/") | keys(max_num_nodes=max_num_nodes))
40+
41+
3242
def v3_dtypes() -> st.SearchStrategy[np.dtype]:
3343
return (
3444
npst.boolean_dtypes()
@@ -88,10 +98,11 @@ def clear_store(x: Store) -> Store:
8898
node_names = st.text(zarr_key_chars, min_size=1).filter(
8999
lambda t: t not in (".", "..") and not t.startswith("__")
90100
)
101+
short_node_names = st.text(zarr_key_chars, max_size=3, min_size=1).filter(
102+
lambda t: t not in (".", "..") and not t.startswith("__")
103+
)
91104
array_names = node_names
92105
attrs = st.none() | st.dictionaries(_attr_keys, _attr_values)
93-
keys = st.lists(node_names, min_size=1).map("/".join)
94-
paths = st.just("/") | keys
95106
# st.builds will only call a new store constructor for different keyword arguments
96107
# i.e. stores.examples() will always return the same object per Store class.
97108
# So we map a clear to reset the store.
@@ -221,7 +232,7 @@ def arrays(
221232
shapes: st.SearchStrategy[tuple[int, ...]] = array_shapes,
222233
compressors: st.SearchStrategy = compressors,
223234
stores: st.SearchStrategy[StoreLike] = stores,
224-
paths: st.SearchStrategy[str | None] = paths,
235+
paths: st.SearchStrategy[str | None] = paths(), # noqa: B008
225236
array_names: st.SearchStrategy = array_names,
226237
arrays: st.SearchStrategy | None = None,
227238
attrs: st.SearchStrategy = attrs,
@@ -286,8 +297,9 @@ def simple_arrays(
286297
return draw(
287298
arrays(
288299
shapes=shapes,
289-
attrs=st.none(),
290300
paths=paths(max_num_nodes=2),
301+
array_names=short_node_names,
302+
attrs=st.none(),
291303
compressors=st.sampled_from([None, "default"]),
292304
)
293305
)

0 commit comments

Comments
 (0)