Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[3.11] gh-105751, test_ctypes: Remove disabled tests (GH-105826) #107484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[3.11] gh-105751, test_ctypes: Remove disabled tests (GH-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.
(cherry picked from commit 8f10140)

Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
vstinner authored and ambv committed Jul 31, 2023
commit bdb4ea0bb85592394fe3f527990375906f68f67b
8 changes: 0 additions & 8 deletions 8 Lib/ctypes/test/test_byteswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ def bin(s):
# For Structures and Unions, these types are created on demand.

class Test(unittest.TestCase):
@unittest.skip('test disabled')
def test_X(self):
print(sys.byteorder, file=sys.stderr)
for i in range(32):
bits = BITS()
setattr(bits, "i%s" % i, 1)
dump(bits)

def test_slots(self):
class BigPoint(BigEndianStructure):
__slots__ = ()
Expand Down
8 changes: 0 additions & 8 deletions 8 Lib/ctypes/test/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ def test_char(self):
self.check_type(c_char, b"x")
self.check_type(c_char, b"a")

# disabled: would now (correctly) raise a RuntimeWarning about
# a memory leak. A callback function cannot return a non-integral
# C type without causing a memory leak.
@unittest.skip('test disabled')
def test_char_p(self):
self.check_type(c_char_p, "abc")
self.check_type(c_char_p, "def")

def test_pyobject(self):
o = ()
from sys import getrefcount as grc
Expand Down
31 changes: 0 additions & 31 deletions 31 Lib/ctypes/test/test_keeprefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,37 +93,6 @@ def test_p_cint(self):
x = pointer(i)
self.assertEqual(x._objects, {'1': i})

class DeletePointerTestCase(unittest.TestCase):
@unittest.skip('test disabled')
def test_X(self):
class X(Structure):
_fields_ = [("p", POINTER(c_char_p))]
x = X()
i = c_char_p("abc def")
from sys import getrefcount as grc
print("2?", grc(i))
x.p = pointer(i)
print("3?", grc(i))
for i in range(320):
c_int(99)
x.p[0]
print(x.p[0])
## del x
## print "2?", grc(i)
## del i
import gc
gc.collect()
for i in range(320):
c_int(99)
x.p[0]
print(x.p[0])
print(x.p.contents)
## print x._objects

x.p[0] = "spam spam"
## print x.p[0]
print("+" * 42)
print(x._objects)

class PointerToStructure(unittest.TestCase):
def test(self):
Expand Down
77 changes: 0 additions & 77 deletions 77 Lib/ctypes/test/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,6 @@ def test_typeerror(self):
self.assertRaises(TypeError, t, "")
self.assertRaises(TypeError, t, None)

@unittest.skip('test disabled')
def test_valid_ranges(self):
# invalid values of the correct type
# raise ValueError (not OverflowError)
for t, (l, h) in zip(unsigned_types, unsigned_ranges):
self.assertRaises(ValueError, t, l-1)
self.assertRaises(ValueError, t, h+1)

def test_from_param(self):
# the from_param class method attribute always
# returns PyCArgObject instances
Expand Down Expand Up @@ -205,19 +197,6 @@ def test_char_from_address(self):
a[0] = ord('?')
self.assertEqual(v.value, b'?')

# array does not support c_bool / 't'
@unittest.skip('test disabled')
def test_bool_from_address(self):
from ctypes import c_bool
from array import array
a = array(c_bool._type_, [True])
v = t.from_address(a.buffer_info()[0])
self.assertEqual(v.value, a[0])
self.assertEqual(type(v) is t)
a[0] = False
self.assertEqual(v.value, a[0])
self.assertEqual(type(v) is t)

def test_init(self):
# c_int() can be initialized from Python's int, and c_int.
# Not from c_long or so, which seems strange, abc should
Expand All @@ -234,62 +213,6 @@ def test_float_overflow(self):
if (hasattr(t, "__ctype_le__")):
self.assertRaises(OverflowError, t.__ctype_le__, big_int)

@unittest.skip('test disabled')
def test_perf(self):
check_perf()

from ctypes import _SimpleCData
class c_int_S(_SimpleCData):
_type_ = "i"
__slots__ = []

def run_test(rep, msg, func, arg=None):
## items = [None] * rep
items = range(rep)
from time import perf_counter as clock
if arg is not None:
start = clock()
for i in items:
func(arg); func(arg); func(arg); func(arg); func(arg)
stop = clock()
else:
start = clock()
for i in items:
func(); func(); func(); func(); func()
stop = clock()
print("%15s: %.2f us" % (msg, ((stop-start)*1e6/5/rep)))

def check_perf():
# Construct 5 objects
from ctypes import c_int

REP = 200000

run_test(REP, "int()", int)
run_test(REP, "int(999)", int)
run_test(REP, "c_int()", c_int)
run_test(REP, "c_int(999)", c_int)
run_test(REP, "c_int_S()", c_int_S)
run_test(REP, "c_int_S(999)", c_int_S)

# Python 2.3 -OO, win2k, P4 700 MHz:
#
# int(): 0.87 us
# int(999): 0.87 us
# c_int(): 3.35 us
# c_int(999): 3.34 us
# c_int_S(): 3.23 us
# c_int_S(999): 3.24 us

# Python 2.2 -OO, win2k, P4 700 MHz:
#
# int(): 0.89 us
# int(999): 0.89 us
# c_int(): 9.99 us
# c_int(999): 10.02 us
# c_int_S(): 9.87 us
# c_int_S(999): 9.85 us

if __name__ == '__main__':
## check_perf()
unittest.main()
9 changes: 0 additions & 9 deletions 9 Lib/ctypes/test/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,6 @@ def get_except(self, func, *args):
except Exception as detail:
return detail.__class__, str(detail)

@unittest.skip('test disabled')
def test_subclass_creation(self):
meta = type(Structure)
# same as 'class X(Structure): pass'
# fails, since we need either a _fields_ or a _abstract_ attribute
cls, msg = self.get_except(meta, "X", (Structure,), {})
self.assertEqual((cls, msg),
(AttributeError, "class must define a '_fields_' attribute"))

def test_abstract_class(self):
class X(Structure):
_abstract_ = "something"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.