3
3
import sys
4
4
import unittest
5
5
from operator import truth
6
- from ctypes import (byref , sizeof , alignment , _SimpleCData ,
6
+ from ctypes import (byref , sizeof , alignment ,
7
7
c_char , c_byte , c_ubyte , c_short , c_ushort , c_int , c_uint ,
8
8
c_long , c_ulong , c_longlong , c_ulonglong ,
9
9
c_float , c_double , c_longdouble , c_bool )
@@ -70,14 +70,6 @@ def test_typeerror(self):
70
70
self .assertRaises (TypeError , t , "" )
71
71
self .assertRaises (TypeError , t , None )
72
72
73
- @unittest .skip ('test disabled' )
74
- def test_valid_ranges (self ):
75
- # invalid values of the correct type
76
- # raise ValueError (not OverflowError)
77
- for t , (l , h ) in zip (unsigned_types , unsigned_ranges ):
78
- self .assertRaises (ValueError , t , l - 1 )
79
- self .assertRaises (ValueError , t , h + 1 )
80
-
81
73
def test_from_param (self ):
82
74
# the from_param class method attribute always
83
75
# returns PyCArgObject instances
@@ -188,17 +180,6 @@ def test_char_from_address(self):
188
180
a [0 ] = ord ('?' )
189
181
self .assertEqual (v .value , b'?' )
190
182
191
- # array does not support c_bool / 't'
192
- @unittest .skip ('test disabled' )
193
- def test_bool_from_address (self ):
194
- a = array .array (c_bool ._type_ , [True ])
195
- v = t .from_address (a .buffer_info ()[0 ])
196
- self .assertEqual (v .value , a [0 ])
197
- self .assertEqual (type (v ) is t )
198
- a [0 ] = False
199
- self .assertEqual (v .value , a [0 ])
200
- self .assertEqual (type (v ) is t )
201
-
202
183
def test_init (self ):
203
184
# c_int() can be initialized from Python's int, and c_int.
204
185
# Not from c_long or so, which seems strange, abc should
@@ -214,63 +195,6 @@ def test_float_overflow(self):
214
195
if (hasattr (t , "__ctype_le__" )):
215
196
self .assertRaises (OverflowError , t .__ctype_le__ , big_int )
216
197
217
- @unittest .skip ('test disabled' )
218
- def test_perf (self ):
219
- check_perf ()
220
-
221
-
222
- class c_int_S (_SimpleCData ):
223
- _type_ = "i"
224
- __slots__ = []
225
-
226
-
227
- def run_test (rep , msg , func , arg = None ):
228
- items = range (rep )
229
- from time import perf_counter as clock
230
- if arg is not None :
231
- start = clock ()
232
- for i in items :
233
- func (arg ); func (arg ); func (arg ); func (arg ); func (arg )
234
- stop = clock ()
235
- else :
236
- start = clock ()
237
- for i in items :
238
- func (); func (); func (); func (); func ()
239
- stop = clock ()
240
- print ("%15s: %.2f us" % (msg , ((stop - start )* 1e6 / 5 / rep )))
241
-
242
-
243
- def check_perf ():
244
- # Construct 5 objects
245
-
246
- REP = 200000
247
-
248
- run_test (REP , "int()" , int )
249
- run_test (REP , "int(999)" , int )
250
- run_test (REP , "c_int()" , c_int )
251
- run_test (REP , "c_int(999)" , c_int )
252
- run_test (REP , "c_int_S()" , c_int_S )
253
- run_test (REP , "c_int_S(999)" , c_int_S )
254
-
255
- # Python 2.3 -OO, win2k, P4 700 MHz:
256
- #
257
- # int(): 0.87 us
258
- # int(999): 0.87 us
259
- # c_int(): 3.35 us
260
- # c_int(999): 3.34 us
261
- # c_int_S(): 3.23 us
262
- # c_int_S(999): 3.24 us
263
-
264
- # Python 2.2 -OO, win2k, P4 700 MHz:
265
- #
266
- # int(): 0.89 us
267
- # int(999): 0.89 us
268
- # c_int(): 9.99 us
269
- # c_int(999): 10.02 us
270
- # c_int_S(): 9.87 us
271
- # c_int_S(999): 9.85 us
272
-
273
198
274
199
if __name__ == '__main__' :
275
- ## check_perf()
276
200
unittest .main ()
0 commit comments