6
6
from pandas ._libs import ops
7
7
8
8
9
- @pytest .fixture (name = "int_max" )
9
+ @pytest .fixture (name = "int_max" , scope = "module" )
10
10
def fixture_int_max () -> int :
11
11
return np .iinfo (np .int64 ).max
12
12
13
13
14
- @pytest .fixture (name = "int_min" )
14
+ @pytest .fixture (name = "int_min" , scope = "module" )
15
15
def fixture_int_min () -> int :
16
16
return np .iinfo (np .int64 ).min
17
17
18
18
19
- @pytest .fixture (name = "overflow_msg" )
19
+ @pytest .fixture (name = "float_max" , scope = "module" )
20
+ def fixture_float_max () -> int :
21
+ return np .finfo (np .float64 ).max
22
+
23
+
24
+ @pytest .fixture (name = "float_min" , scope = "module" )
25
+ def fixture_float_min () -> int :
26
+ return np .finfo (np .float64 ).min
27
+
28
+
29
+ @pytest .fixture (name = "overflow_msg" , scope = "module" )
20
30
def fixture_overflow_msg () -> str :
21
31
return "|" .join (
22
32
(
@@ -26,33 +36,108 @@ def fixture_overflow_msg() -> str:
26
36
)
27
37
28
38
29
- def test_raises_for_too_large_arg (int_max : int , overflow_msg : str ):
30
- with pytest .raises (OverflowError , match = overflow_msg ):
31
- ops .calculate (operator .add , int_max + 1 , 1 )
32
-
33
- with pytest .raises (OverflowError , match = overflow_msg ):
34
- ops .calculate (operator .add , 1 , int_max + 1 )
39
+ class TestCalcIntInt :
40
+ def test_raises_for_too_large_arg (self , int_max : int , overflow_msg : str ):
41
+ with pytest .raises (OverflowError , match = overflow_msg ):
42
+ ops .calc_int_int (operator .add , int_max + 1 , 1 )
35
43
44
+ with pytest .raises (OverflowError , match = overflow_msg ):
45
+ ops .calc_int_int (operator .add , 1 , int_max + 1 )
36
46
37
- def test_raises_for_too_small_arg (int_min : int , overflow_msg : str ):
38
- with pytest .raises (OverflowError , match = overflow_msg ):
39
- ops .calculate (operator .add , int_min - 1 , 1 )
47
+ def test_raises_for_too_small_arg (self , int_min : int , overflow_msg : str ):
48
+ with pytest .raises (OverflowError , match = overflow_msg ):
49
+ ops .calc_int_int (operator .add , int_min - 1 , 1 )
40
50
41
- with pytest .raises (OverflowError , match = overflow_msg ):
42
- ops .calculate (operator .add , 1 , int_min - 1 )
51
+ with pytest .raises (OverflowError , match = overflow_msg ):
52
+ ops .calc_int_int (operator .add , 1 , int_min - 1 )
43
53
54
+ def test_raises_for_too_large_result (self , int_max : int , overflow_msg : str ):
55
+ with pytest .raises (OverflowError , match = overflow_msg ):
56
+ ops .calc_int_int (operator .add , int_max , 1 )
44
57
45
- def test_raises_for_too_large_result (int_max : int , overflow_msg : str ):
46
- with pytest .raises (OverflowError , match = overflow_msg ):
47
- ops .calculate (operator .add , int_max , 1 )
58
+ with pytest .raises (OverflowError , match = overflow_msg ):
59
+ ops .calc_int_int (operator .add , 1 , int_max )
48
60
49
- with pytest .raises (OverflowError , match = overflow_msg ):
50
- ops .calculate (operator .add , 1 , int_max )
61
+ def test_raises_for_too_small_result (self , int_min : int , overflow_msg : str ):
62
+ with pytest .raises (OverflowError , match = overflow_msg ):
63
+ ops .calc_int_int (operator .sub , int_min , 1 )
51
64
65
+ with pytest .raises (OverflowError , match = overflow_msg ):
66
+ ops .calc_int_int (operator .sub , 1 , int_min )
52
67
53
- def test_raises_for_too_small_result (int_min : int , overflow_msg : str ):
54
- with pytest .raises (OverflowError , match = overflow_msg ):
55
- ops .calculate (operator .sub , int_min , 1 )
56
68
57
- with pytest .raises (OverflowError , match = overflow_msg ):
58
- ops .calculate (operator .sub , 1 , int_min )
69
+ class TestCalcIntFloat :
70
+ @pytest .mark .parametrize (
71
+ "op,lval,rval,expected" ,
72
+ (
73
+ (operator .add , 1 , 1.0 , 2 ),
74
+ (operator .sub , 2 , 1.0 , 1 ),
75
+ (operator .mul , 1 , 2.0 , 2 ),
76
+ (operator .truediv , 1 , 0.5 , 2 ),
77
+ ),
78
+ ids = ("+" , "-" , "*" , "/" ),
79
+ )
80
+ def test_arithmetic_ops (self , op , lval : int , rval : float , expected : int ):
81
+ result = ops .calc_int_float (op , lval , rval )
82
+
83
+ assert result == expected
84
+ assert isinstance (result , int )
85
+
86
+ def test_raises_for_too_large_arg (
87
+ self ,
88
+ int_max : int ,
89
+ float_max : float ,
90
+ overflow_msg : str ,
91
+ ):
92
+ with pytest .raises (OverflowError , match = overflow_msg ):
93
+ ops .calc_int_float (operator .add , int_max + 1 , 1 )
94
+
95
+ with pytest .raises (OverflowError , match = overflow_msg ):
96
+ ops .calc_int_float (operator .add , 1 , float_max + 1 )
97
+
98
+ def test_raises_for_too_small_arg (
99
+ self ,
100
+ int_min : int ,
101
+ float_min : float ,
102
+ overflow_msg : str ,
103
+ ):
104
+ with pytest .raises (OverflowError , match = overflow_msg ):
105
+ ops .calc_int_float (operator .add , int_min - 1 , 1 )
106
+
107
+ with pytest .raises (OverflowError , match = overflow_msg ):
108
+ ops .calc_int_float (operator .add , 1 , float_min - 1 )
109
+
110
+ def test_raises_for_too_large_result (
111
+ self ,
112
+ int_max : int ,
113
+ float_max : float ,
114
+ overflow_msg : str ,
115
+ ):
116
+ with pytest .raises (OverflowError , match = overflow_msg ):
117
+ ops .calc_int_float (operator .add , int_max , 1 )
118
+
119
+ with pytest .raises (OverflowError , match = overflow_msg ):
120
+ ops .calc_int_float (operator .add , 1 , float_max )
121
+
122
+ @pytest .mark .parametrize (
123
+ "value" ,
124
+ (
125
+ pytest .param (
126
+ 1024 ,
127
+ marks = pytest .mark .xfail (
128
+ reason = "TBD" ,
129
+ raises = pytest .fail .Exception ,
130
+ strict = True ,
131
+ ),
132
+ ),
133
+ 1024.1 ,
134
+ ),
135
+ )
136
+ def test_raises_for_most_too_small_results (
137
+ self ,
138
+ value : float ,
139
+ int_min : int ,
140
+ overflow_msg : str ,
141
+ ):
142
+ with pytest .raises (OverflowError , match = overflow_msg ):
143
+ ops .calc_int_float (operator .sub , int_min , value )
0 commit comments