@@ -24,7 +24,9 @@ def squeeze(x, /, axis):
24
24
from typing import Any , Callable , Dict , List , Literal , Sequence , get_args
25
25
26
26
import pytest
27
+ from hypothesis import given , note , settings
27
28
from hypothesis import strategies as st
29
+ from hypothesis .strategies import DataObject
28
30
29
31
from . import dtype_helpers as dh
30
32
from . import hypothesis_helpers as hh
@@ -117,7 +119,11 @@ def make_pretty_func(func_name: str, args: Sequence[Any], kwargs: Dict[str, Any]
117
119
matrixy_funcs += ["__matmul__" , "triu" , "tril" ]
118
120
119
121
120
- def _test_uninspectable_func (func_name : str , func : Callable , stub_sig : Signature ):
122
+ @given (data = st .data ())
123
+ @settings (max_examples = 1 )
124
+ def _test_uninspectable_func (
125
+ func_name : str , func : Callable , stub_sig : Signature , data : DataObject
126
+ ):
121
127
skip_msg = (
122
128
f"Signature for { func_name } () is not inspectable "
123
129
"and is too troublesome to test for otherwise"
@@ -145,12 +151,16 @@ def _test_uninspectable_func(func_name: str, func: Callable, stub_sig: Signature
145
151
value = param .default
146
152
elif param .name in ["x" , "x1" ]:
147
153
dtypes = get_dtypes_strategy (func_name )
148
- value = xps .arrays (dtype = dtypes , shape = hh .shapes (min_side = 1 )).example ()
154
+ value = data .draw (
155
+ xps .arrays (dtype = dtypes , shape = hh .shapes (min_side = 1 )), label = param .name
156
+ )
149
157
elif param .name == "x2" :
150
158
# sanity check
151
159
assert "x1" in [p .name for p in param_to_value .keys ()]
152
160
x1 = next (v for p , v in param_to_value .items () if p .name == "x1" )
153
- value = xps .arrays (dtype = x1 .dtype , shape = x1 .shape ).example ()
161
+ value = data .draw (
162
+ xps .arrays (dtype = x1 .dtype , shape = x1 .shape ), label = param .name
163
+ )
154
164
else :
155
165
pytest .skip (
156
166
skip_msg + f" (because no default was found for argument { param .name } )"
@@ -164,7 +174,7 @@ def _test_uninspectable_func(func_name: str, func: Callable, stub_sig: Signature
164
174
p .name : v for p , v in param_to_value .items () if p .kind == Parameter .KEYWORD_ONLY
165
175
}
166
176
f_func = make_pretty_func (func_name , args , kwargs )
167
- print (f"trying { f_func } " )
177
+ note (f"trying { f_func } " )
168
178
func (* args , ** kwargs )
169
179
170
180
@@ -217,9 +227,11 @@ def test_extension_func_signature(extension: str, stub: FunctionType):
217
227
218
228
219
229
@pytest .mark .parametrize ("stub" , array_methods , ids = lambda f : f .__name__ )
220
- def test_array_method_signature (stub : FunctionType ):
230
+ @given (st .data ())
231
+ @settings (max_examples = 1 )
232
+ def test_array_method_signature (stub : FunctionType , data : DataObject ):
221
233
dtypes = get_dtypes_strategy (stub .__name__ )
222
- x = xps .arrays (dtype = dtypes , shape = hh .shapes (min_side = 1 )). example ( )
234
+ x = data . draw ( xps .arrays (dtype = dtypes , shape = hh .shapes (min_side = 1 )), label = "x" )
223
235
assert hasattr (x , stub .__name__ ), f"{ stub .__name__ } not found in array object { x !r} "
224
236
method = getattr (x , stub .__name__ )
225
237
# Ignore 'self' arg in stub, which won't be present in instantiated objects.
0 commit comments