Skip to content

Commit 6883a0e

Browse files
committed
Reduce freqquency of clear
1 parent 416d2c2 commit 6883a0e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/zarr/testing/stateful.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import builtins
2-
from typing import Any
2+
import functools
3+
import random
4+
from collections.abc import Callable
5+
from typing import Any, TypeVar, cast
36

47
import hypothesis.extra.numpy as npst
58
import hypothesis.strategies as st
@@ -34,6 +37,23 @@
3437

3538
MAX_BINARY_SIZE = 100
3639

40+
F = TypeVar("F", bound=Callable[..., Any])
41+
42+
43+
def with_frequency(frequency: float) -> Callable[[F], F]:
44+
def decorator(func: F) -> F:
45+
@functools.wraps(func)
46+
def wrapper(*args: Any, **kwargs: Any) -> Any:
47+
return func(*args, **kwargs)
48+
49+
@precondition
50+
def frequency_check(f: Any) -> Any:
51+
return random.random() < frequency
52+
53+
return cast(F, frequency_check(wrapper))
54+
55+
return decorator
56+
3757

3858
def split_prefix_name(path: str) -> tuple[str, str]:
3959
split = path.rsplit("/", maxsplit=1)
@@ -129,6 +149,7 @@ def add_array(
129149
self.all_arrays.add(path)
130150

131151
@rule()
152+
@with_frequency(0.25)
132153
def clear(self) -> None:
133154
note("clearing")
134155
import zarr

0 commit comments

Comments
 (0)