11import unittest
22from test import test_support
33from _testcapi import getargs_keywords
4-
54import warnings
6- warnings .filterwarnings ("ignore" ,
7- category = DeprecationWarning ,
8- message = ".*integer argument expected, got float" ,
9- module = __name__ )
10- warnings .filterwarnings ("ignore" ,
11- category = DeprecationWarning ,
12- message = ".*integer argument expected, got float" ,
13- module = "unittest" )
145
156"""
167> How about the following counterproposal. This also changes some of
@@ -68,7 +59,7 @@ class Unsigned_TestCase(unittest.TestCase):
6859 def test_b (self ):
6960 from _testcapi import getargs_b
7061 # b returns 'unsigned char', and does range checking (0 ... UCHAR_MAX)
71- self .assertEqual ( 3 , getargs_b ( 3.14 ) )
62+ self .assertRaises ( TypeError , getargs_b , 3.14 )
7263 self .assertEqual (99 , getargs_b (Long ()))
7364 self .assertEqual (99 , getargs_b (Int ()))
7465
@@ -84,7 +75,7 @@ def test_b(self):
8475 def test_B (self ):
8576 from _testcapi import getargs_B
8677 # B returns 'unsigned char', no range checking
87- self .assertEqual ( 3 , getargs_B ( 3.14 ) )
78+ self .assertRaises ( TypeError , getargs_B , 3.14 )
8879 self .assertEqual (99 , getargs_B (Long ()))
8980 self .assertEqual (99 , getargs_B (Int ()))
9081
@@ -101,7 +92,7 @@ def test_B(self):
10192 def test_H (self ):
10293 from _testcapi import getargs_H
10394 # H returns 'unsigned short', no range checking
104- self .assertEqual ( 3 , getargs_H ( 3.14 ) )
95+ self .assertRaises ( TypeError , getargs_H , 3.14 )
10596 self .assertEqual (99 , getargs_H (Long ()))
10697 self .assertEqual (99 , getargs_H (Int ()))
10798
@@ -118,7 +109,7 @@ def test_H(self):
118109 def test_I (self ):
119110 from _testcapi import getargs_I
120111 # I returns 'unsigned int', no range checking
121- self .assertEqual ( 3 , getargs_I ( 3.14 ) )
112+ self .assertRaises ( TypeError , getargs_I , 3.14 )
122113 self .assertEqual (99 , getargs_I (Long ()))
123114 self .assertEqual (99 , getargs_I (Int ()))
124115
@@ -154,7 +145,7 @@ class Signed_TestCase(unittest.TestCase):
154145 def test_h (self ):
155146 from _testcapi import getargs_h
156147 # h returns 'short', and does range checking (SHRT_MIN ... SHRT_MAX)
157- self .assertEqual ( 3 , getargs_h ( 3.14 ) )
148+ self .assertRaises ( TypeError , getargs_h , 3.14 )
158149 self .assertEqual (99 , getargs_h (Long ()))
159150 self .assertEqual (99 , getargs_h (Int ()))
160151
@@ -170,7 +161,7 @@ def test_h(self):
170161 def test_i (self ):
171162 from _testcapi import getargs_i
172163 # i returns 'int', and does range checking (INT_MIN ... INT_MAX)
173- self .assertEqual ( 3 , getargs_i ( 3.14 ) )
164+ self .assertRaises ( TypeError , getargs_i , 3.14 )
174165 self .assertEqual (99 , getargs_i (Long ()))
175166 self .assertEqual (99 , getargs_i (Int ()))
176167
@@ -186,7 +177,7 @@ def test_i(self):
186177 def test_l (self ):
187178 from _testcapi import getargs_l
188179 # l returns 'long', and does range checking (LONG_MIN ... LONG_MAX)
189- self .assertEqual ( 3 , getargs_l ( 3.14 ) )
180+ self .assertRaises ( TypeError , getargs_l , 3.14 )
190181 self .assertEqual (99 , getargs_l (Long ()))
191182 self .assertEqual (99 , getargs_l (Int ()))
192183
@@ -203,7 +194,7 @@ def test_n(self):
203194 from _testcapi import getargs_n
204195 # n returns 'Py_ssize_t', and does range checking
205196 # (PY_SSIZE_T_MIN ... PY_SSIZE_T_MAX)
206- self .assertEqual ( 3 , getargs_n ( 3.14 ) )
197+ self .assertRaises ( TypeError , getargs_n , 3.14 )
207198 self .assertEqual (99 , getargs_n (Long ()))
208199 self .assertEqual (99 , getargs_n (Int ()))
209200
@@ -220,9 +211,24 @@ def test_n(self):
220211class LongLong_TestCase (unittest .TestCase ):
221212 def test_L (self ):
222213 from _testcapi import getargs_L
223- # L returns 'long long', and does range checking (LLONG_MIN ... LLONG_MAX)
214+ # L returns 'long long', and does range checking (LLONG_MIN
215+ # ... LLONG_MAX)
216+ with warnings .catch_warnings ():
217+ warnings .filterwarnings (
218+ "ignore" ,
219+ category = DeprecationWarning ,
220+ message = ".*integer argument expected, got float" ,
221+ module = __name__ )
222+ self .assertEqual (3 , getargs_L (3.14 ))
223+ with warnings .catch_warnings ():
224+ warnings .filterwarnings (
225+ "error" ,
226+ category = DeprecationWarning ,
227+ message = ".*integer argument expected, got float" ,
228+ module = "unittest" )
229+ self .assertRaises (DeprecationWarning , getargs_L , 3.14 )
230+
224231 self .assertRaises (TypeError , getargs_L , "Hello" )
225- self .assertEqual (3 , getargs_L (3.14 ))
226232 self .assertEqual (99 , getargs_L (Long ()))
227233 self .assertEqual (99 , getargs_L (Int ()))
228234
0 commit comments