Skip to content

Commit 1d21c99

Browse files
ambvvstinner
andauthored
[3.12] gh-105751, test_ctypes: Remove disabled tests (GH-105826) (#107483)
* 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. (cherry picked from commit 8f10140) Co-authored-by: Victor Stinner <vstinner@python.org>
1 parent f9f9bc9 commit 1d21c99

File tree

5 files changed

+0
-133
lines changed

5 files changed

+0
-133
lines changed

Lib/test/test_ctypes/test_byteswap.py

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

1616
class Test(unittest.TestCase):
17-
@unittest.skip('test disabled')
18-
def test_X(self):
19-
print(sys.byteorder, file=sys.stderr)
20-
for i in range(32):
21-
bits = BITS()
22-
setattr(bits, "i%s" % i, 1)
23-
dump(bits)
24-
2517
def test_slots(self):
2618
class BigPoint(BigEndianStructure):
2719
__slots__ = ()

Lib/test/test_ctypes/test_callbacks.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ def test_char(self):
9393
self.check_type(c_char, b"x")
9494
self.check_type(c_char, b"a")
9595

96-
# disabled: would now (correctly) raise a RuntimeWarning about
97-
# a memory leak. A callback function cannot return a non-integral
98-
# C type without causing a memory leak.
99-
@unittest.skip('test disabled')
100-
def test_char_p(self):
101-
self.check_type(c_char_p, "abc")
102-
self.check_type(c_char_p, "def")
103-
10496
def test_pyobject(self):
10597
o = ()
10698
from sys import getrefcount as grc

Lib/test/test_ctypes/test_keeprefs.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,6 @@ def test_p_cint(self):
9393
x = pointer(i)
9494
self.assertEqual(x._objects, {'1': i})
9595

96-
class DeletePointerTestCase(unittest.TestCase):
97-
@unittest.skip('test disabled')
98-
def test_X(self):
99-
class X(Structure):
100-
_fields_ = [("p", POINTER(c_char_p))]
101-
x = X()
102-
i = c_char_p("abc def")
103-
from sys import getrefcount as grc
104-
print("2?", grc(i))
105-
x.p = pointer(i)
106-
print("3?", grc(i))
107-
for i in range(320):
108-
c_int(99)
109-
x.p[0]
110-
print(x.p[0])
111-
## del x
112-
## print "2?", grc(i)
113-
## del i
114-
import gc
115-
gc.collect()
116-
for i in range(320):
117-
c_int(99)
118-
x.p[0]
119-
print(x.p[0])
120-
print(x.p.contents)
121-
## print x._objects
122-
123-
x.p[0] = "spam spam"
124-
## print x.p[0]
125-
print("+" * 42)
126-
print(x._objects)
12796

12897
class PointerToStructure(unittest.TestCase):
12998
def test(self):

Lib/test/test_ctypes/test_numbers.py

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,6 @@ def test_typeerror(self):
8282
self.assertRaises(TypeError, t, "")
8383
self.assertRaises(TypeError, t, None)
8484

85-
@unittest.skip('test disabled')
86-
def test_valid_ranges(self):
87-
# invalid values of the correct type
88-
# raise ValueError (not OverflowError)
89-
for t, (l, h) in zip(unsigned_types, unsigned_ranges):
90-
self.assertRaises(ValueError, t, l-1)
91-
self.assertRaises(ValueError, t, h+1)
92-
9385
def test_from_param(self):
9486
# the from_param class method attribute always
9587
# returns PyCArgObject instances
@@ -205,19 +197,6 @@ def test_char_from_address(self):
205197
a[0] = ord('?')
206198
self.assertEqual(v.value, b'?')
207199

208-
# array does not support c_bool / 't'
209-
@unittest.skip('test disabled')
210-
def test_bool_from_address(self):
211-
from ctypes import c_bool
212-
from array import array
213-
a = array(c_bool._type_, [True])
214-
v = t.from_address(a.buffer_info()[0])
215-
self.assertEqual(v.value, a[0])
216-
self.assertEqual(type(v) is t)
217-
a[0] = False
218-
self.assertEqual(v.value, a[0])
219-
self.assertEqual(type(v) is t)
220-
221200
def test_init(self):
222201
# c_int() can be initialized from Python's int, and c_int.
223202
# Not from c_long or so, which seems strange, abc should
@@ -234,62 +213,6 @@ def test_float_overflow(self):
234213
if (hasattr(t, "__ctype_le__")):
235214
self.assertRaises(OverflowError, t.__ctype_le__, big_int)
236215

237-
@unittest.skip('test disabled')
238-
def test_perf(self):
239-
check_perf()
240-
241-
from ctypes import _SimpleCData
242-
class c_int_S(_SimpleCData):
243-
_type_ = "i"
244-
__slots__ = []
245-
246-
def run_test(rep, msg, func, arg=None):
247-
## items = [None] * rep
248-
items = range(rep)
249-
from time import perf_counter as clock
250-
if arg is not None:
251-
start = clock()
252-
for i in items:
253-
func(arg); func(arg); func(arg); func(arg); func(arg)
254-
stop = clock()
255-
else:
256-
start = clock()
257-
for i in items:
258-
func(); func(); func(); func(); func()
259-
stop = clock()
260-
print("%15s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))
261-
262-
def check_perf():
263-
# Construct 5 objects
264-
from ctypes import c_int
265-
266-
REP = 200000
267-
268-
run_test(REP, "int()", int)
269-
run_test(REP, "int(999)", int)
270-
run_test(REP, "c_int()", c_int)
271-
run_test(REP, "c_int(999)", c_int)
272-
run_test(REP, "c_int_S()", c_int_S)
273-
run_test(REP, "c_int_S(999)", c_int_S)
274-
275-
# Python 2.3 -OO, win2k, P4 700 MHz:
276-
#
277-
# int(): 0.87 us
278-
# int(999): 0.87 us
279-
# c_int(): 3.35 us
280-
# c_int(999): 3.34 us
281-
# c_int_S(): 3.23 us
282-
# c_int_S(999): 3.24 us
283-
284-
# Python 2.2 -OO, win2k, P4 700 MHz:
285-
#
286-
# int(): 0.89 us
287-
# int(999): 0.89 us
288-
# c_int(): 9.99 us
289-
# c_int(999): 10.02 us
290-
# c_int_S(): 9.87 us
291-
# c_int_S(999): 9.85 us
292216

293217
if __name__ == '__main__':
294-
## check_perf()
295218
unittest.main()

Lib/test/test_ctypes/test_structures.py

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

362-
@unittest.skip('test disabled')
363-
def test_subclass_creation(self):
364-
meta = type(Structure)
365-
# same as 'class X(Structure): pass'
366-
# fails, since we need either a _fields_ or a _abstract_ attribute
367-
cls, msg = self.get_except(meta, "X", (Structure,), {})
368-
self.assertEqual((cls, msg),
369-
(AttributeError, "class must define a '_fields_' attribute"))
370-
371362
def test_abstract_class(self):
372363
class X(Structure):
373364
_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