File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 11import 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
47import hypothesis .extra .numpy as npst
58import hypothesis .strategies as st
3437
3538MAX_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
3858def 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
You can’t perform that action at this time.
0 commit comments