Skip to content

Commit 8f10140

Browse files
authored
gh-105751, test_ctypes: Remove disabled tests (#105826)
* The following tests were disabled since the initial ctypes commit in 2006, commit babddfc: * Callbacks.test_char_p() * DeletePointerTestCase.test_X() * NumberTestCase.test_perf() * StructureTestCase.test_subclass_creation() * Tests.test_X() of test_byteswap * NumberTestCase.test_bool_from_address() was disabled in 2007 by commit 5dc4fe0. * Remove check_perf() and run_test() of test_numbers.
1 parent 09ce8c3 commit 8f10140

File tree

5 files changed

+2
-131
lines changed

5 files changed

+2
-131
lines changed

Lib/test/test_ctypes/test_byteswap.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ def bin(s):
2525
# For Structures and Unions, these types are created on demand.
2626

2727
class Test(unittest.TestCase):
28-
@unittest.skip('test disabled')
29-
def test_X(self):
30-
print(sys.byteorder, file=sys.stderr)
31-
for i in range(32):
32-
bits = BITS()
33-
setattr(bits, "i%s" % i, 1)
34-
dump(bits)
35-
3628
def test_slots(self):
3729
class BigPoint(BigEndianStructure):
3830
__slots__ = ()

Lib/test/test_ctypes/test_callbacks.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from _ctypes import CTYPES_MAX_ARGCOUNT
99
from ctypes import (CDLL, cdll, Structure, CFUNCTYPE,
1010
ArgumentError, POINTER, sizeof,
11-
c_byte, c_ubyte, c_char, c_char_p,
11+
c_byte, c_ubyte, c_char,
1212
c_short, c_ushort, c_int, c_uint,
1313
c_long, c_longlong, c_ulonglong, c_ulong,
1414
c_float, c_double, c_longdouble, py_object)
@@ -92,14 +92,6 @@ def test_char(self):
9292
self.check_type(c_char, b"x")
9393
self.check_type(c_char, b"a")
9494

95-
# disabled: would now (correctly) raise a RuntimeWarning about
96-
# a memory leak. A callback function cannot return a non-integral
97-
# C type without causing a memory leak.
98-
@unittest.skip('test disabled')
99-
def test_char_p(self):
100-
self.check_type(c_char_p, "abc")
101-
self.check_type(c_char_p, "def")
102-
10395
def test_pyobject(self):
10496
o = ()
10597
for o in (), [], object():

Lib/test/test_ctypes/test_keeprefs.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import gc
2-
import sys
31
import unittest
42
from ctypes import (Structure, POINTER, pointer, _pointer_type_cache,
53
c_char_p, c_int)
@@ -101,32 +99,6 @@ def test_p_cint(self):
10199
self.assertEqual(x._objects, {'1': i})
102100

103101

104-
class DeletePointerTestCase(unittest.TestCase):
105-
@unittest.skip('test disabled')
106-
def test_X(self):
107-
class X(Structure):
108-
_fields_ = [("p", POINTER(c_char_p))]
109-
x = X()
110-
i = c_char_p("abc def")
111-
print("2?", sys.getrefcount(i))
112-
x.p = pointer(i)
113-
print("3?", sys.getrefcount(i))
114-
for i in range(320):
115-
c_int(99)
116-
x.p[0]
117-
print(x.p[0])
118-
gc.collect()
119-
for i in range(320):
120-
c_int(99)
121-
x.p[0]
122-
print(x.p[0])
123-
print(x.p.contents)
124-
125-
x.p[0] = "spam spam"
126-
print("+" * 42)
127-
print(x._objects)
128-
129-
130102
class PointerToStructure(unittest.TestCase):
131103
def test(self):
132104
class POINT(Structure):

Lib/test/test_ctypes/test_numbers.py

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import unittest
55
from operator import truth
6-
from ctypes import (byref, sizeof, alignment, _SimpleCData,
6+
from ctypes import (byref, sizeof, alignment,
77
c_char, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
88
c_long, c_ulong, c_longlong, c_ulonglong,
99
c_float, c_double, c_longdouble, c_bool)
@@ -70,14 +70,6 @@ def test_typeerror(self):
7070
self.assertRaises(TypeError, t, "")
7171
self.assertRaises(TypeError, t, None)
7272

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-
8173
def test_from_param(self):
8274
# the from_param class method attribute always
8375
# returns PyCArgObject instances
@@ -188,17 +180,6 @@ def test_char_from_address(self):
188180
a[0] = ord('?')
189181
self.assertEqual(v.value, b'?')
190182

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-
202183
def test_init(self):
203184
# c_int() can be initialized from Python's int, and c_int.
204185
# Not from c_long or so, which seems strange, abc should
@@ -214,63 +195,6 @@ def test_float_overflow(self):
214195
if (hasattr(t, "__ctype_le__")):
215196
self.assertRaises(OverflowError, t.__ctype_le__, big_int)
216197

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-
273198

274199
if __name__ == '__main__':
275-
## check_perf()
276200
unittest.main()

Lib/test/test_ctypes/test_structures.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,6 @@ def get_except(self, func, *args):
357357
except Exception as detail:
358358
return detail.__class__, str(detail)
359359

360-
@unittest.skip('test disabled')
361-
def test_subclass_creation(self):
362-
meta = type(Structure)
363-
# same as 'class X(Structure): pass'
364-
# fails, since we need either a _fields_ or a _abstract_ attribute
365-
cls, msg = self.get_except(meta, "X", (Structure,), {})
366-
self.assertEqual((cls, msg),
367-
(AttributeError, "class must define a '_fields_' attribute"))
368-
369360
def test_abstract_class(self):
370361
class X(Structure):
371362
_abstract_ = "something"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy