|
29 | 29 | ) |
30 | 30 |
|
31 | 31 |
|
| 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 | + |
32 | 42 | def v3_dtypes() -> st.SearchStrategy[np.dtype]: |
33 | 43 | return ( |
34 | 44 | npst.boolean_dtypes() |
@@ -88,10 +98,11 @@ def clear_store(x: Store) -> Store: |
88 | 98 | node_names = st.text(zarr_key_chars, min_size=1).filter( |
89 | 99 | lambda t: t not in (".", "..") and not t.startswith("__") |
90 | 100 | ) |
| 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 | +) |
91 | 104 | array_names = node_names |
92 | 105 | 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 |
95 | 106 | # st.builds will only call a new store constructor for different keyword arguments |
96 | 107 | # i.e. stores.examples() will always return the same object per Store class. |
97 | 108 | # So we map a clear to reset the store. |
@@ -221,7 +232,7 @@ def arrays( |
221 | 232 | shapes: st.SearchStrategy[tuple[int, ...]] = array_shapes, |
222 | 233 | compressors: st.SearchStrategy = compressors, |
223 | 234 | stores: st.SearchStrategy[StoreLike] = stores, |
224 | | - paths: st.SearchStrategy[str | None] = paths, |
| 235 | + paths: st.SearchStrategy[str | None] = paths(), # noqa: B008 |
225 | 236 | array_names: st.SearchStrategy = array_names, |
226 | 237 | arrays: st.SearchStrategy | None = None, |
227 | 238 | attrs: st.SearchStrategy = attrs, |
@@ -286,8 +297,9 @@ def simple_arrays( |
286 | 297 | return draw( |
287 | 298 | arrays( |
288 | 299 | shapes=shapes, |
289 | | - attrs=st.none(), |
290 | 300 | paths=paths(max_num_nodes=2), |
| 301 | + array_names=short_node_names, |
| 302 | + attrs=st.none(), |
291 | 303 | compressors=st.sampled_from([None, "default"]), |
292 | 304 | ) |
293 | 305 | ) |
|
0 commit comments