5
5
from typing import Iterator , TypeVar , Tuple , Callable , Type , Union
6
6
7
7
import pytest
8
- from hypothesis import assume , given
8
+ from hypothesis import assume , given , reject
9
9
from hypothesis import strategies as st
10
10
11
11
from . import _array_module as xp
@@ -81,7 +81,7 @@ def test_func_returns_array_with_correct_dtype(
81
81
x = data .draw (
82
82
xps .arrays (dtype = in_dtypes [0 ], shape = hh .shapes ).filter (x_filter ), label = 'x'
83
83
)
84
- out = func ( x )
84
+ arrays = [ x ]
85
85
else :
86
86
arrays = []
87
87
shapes = data .draw (
@@ -92,7 +92,10 @@ def test_func_returns_array_with_correct_dtype(
92
92
xps .arrays (dtype = dtype , shape = shape ).filter (x_filter ), label = f'x{ i } '
93
93
)
94
94
arrays .append (x )
95
+ try :
95
96
out = func (* arrays )
97
+ except OverflowError :
98
+ reject ()
96
99
assert out .dtype == out_dtype , f'{ out .dtype = !s} , but should be { out_dtype } '
97
100
98
101
@@ -144,21 +147,23 @@ def gen_op_params() -> Iterator[Tuple[str, Tuple[DT, ...], DT, Callable]]:
144
147
def test_operator_returns_array_with_correct_dtype (
145
148
expr , in_dtypes , out_dtype , x_filter , data
146
149
):
150
+ locals_ = {}
147
151
if len (in_dtypes ) == 1 :
148
- x = data .draw (
152
+ locals_ [ 'x' ] = data .draw (
149
153
xps .arrays (dtype = in_dtypes [0 ], shape = hh .shapes ).filter (x_filter ), label = 'x'
150
154
)
151
- out = eval (expr , {'x' : x })
152
155
else :
153
- locals_ = {}
154
156
shapes = data .draw (
155
157
hh .mutually_broadcastable_shapes (len (in_dtypes )), label = 'shapes'
156
158
)
157
159
for i , (dtype , shape ) in enumerate (zip (in_dtypes , shapes ), 1 ):
158
160
locals_ [f'x{ i } ' ] = data .draw (
159
161
xps .arrays (dtype = dtype , shape = shape ).filter (x_filter ), label = f'x{ i } '
160
162
)
163
+ try :
161
164
out = eval (expr , locals_ )
165
+ except OverflowError :
166
+ reject ()
162
167
assert out .dtype == out_dtype , f'{ out .dtype = !s} , but should be { out_dtype } '
163
168
164
169
@@ -197,7 +202,10 @@ def test_inplace_operator_returns_array_with_correct_dtype(
197
202
xps .arrays (dtype = in_dtypes [1 ], shape = shapes [1 ]).filter (x_filter ), label = 'x2'
198
203
)
199
204
locals_ = {'x1' : x1 , 'x2' : x2 }
200
- exec (expr , locals_ )
205
+ try :
206
+ exec (expr , locals_ )
207
+ except OverflowError :
208
+ reject ()
201
209
x1 = locals_ ['x1' ]
202
210
assert x1 .dtype == out_dtype , f'{ x1 .dtype = !s} , but should be { out_dtype } '
203
211
@@ -239,7 +247,7 @@ def test_binary_operator_promotes_python_scalars(
239
247
try :
240
248
out = eval (expr , {'x' : x , 's' : s })
241
249
except OverflowError :
242
- assume ( False )
250
+ reject ( )
243
251
assert out .dtype == out_dtype , f'{ out .dtype = !s} , but should be { out_dtype } '
244
252
245
253
@@ -271,7 +279,7 @@ def test_inplace_operator_promotes_python_scalars(
271
279
try :
272
280
exec (expr , locals_ )
273
281
except OverflowError :
274
- assume ( False )
282
+ reject ( )
275
283
x = locals_ ['x' ]
276
284
assert x .dtype == dtype , f'{ x .dtype = !s} , but should be { dtype } '
277
285
0 commit comments