mirror of
https://github.com/python/cpython.git
synced 2025-11-09 22:16:39 +00:00
Plug some refcount leaks when tests are run repeatedly.
This commit is contained in:
parent
abb903fd54
commit
a022789ab3
2 changed files with 21 additions and 16 deletions
|
|
@ -3,16 +3,16 @@ import sys
|
||||||
|
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class CHECKED(c_int):
|
||||||
|
|
||||||
def test_checkretval(self):
|
|
||||||
|
|
||||||
class CHECKED(c_int):
|
|
||||||
def _check_retval_(value):
|
def _check_retval_(value):
|
||||||
# Receives a CHECKED instance.
|
# Receives a CHECKED instance.
|
||||||
return str(value.value)
|
return str(value.value)
|
||||||
_check_retval_ = staticmethod(_check_retval_)
|
_check_retval_ = staticmethod(_check_retval_)
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_checkretval(self):
|
||||||
|
|
||||||
import _ctypes_test
|
import _ctypes_test
|
||||||
dll = cdll.load(_ctypes_test.__file__)
|
dll = cdll.load(_ctypes_test.__file__)
|
||||||
self.failUnlessEqual(42, dll._testfunc_p_p(42))
|
self.failUnlessEqual(42, dll._testfunc_p_p(42))
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,28 @@
|
||||||
from ctypes import *
|
from ctypes import *
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
nums = [c_byte, c_short, c_int, c_long, c_longlong,
|
subclasses = []
|
||||||
|
for base in [c_byte, c_short, c_int, c_long, c_longlong,
|
||||||
c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong,
|
c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong,
|
||||||
c_float, c_double]
|
c_float, c_double]:
|
||||||
|
class X(base):
|
||||||
|
pass
|
||||||
|
subclasses.append(X)
|
||||||
|
|
||||||
|
class X(c_char):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# This test checks if the __repr__ is correct for subclasses of simple types
|
||||||
|
|
||||||
class ReprTest(unittest.TestCase):
|
class ReprTest(unittest.TestCase):
|
||||||
def test_numbers(self):
|
def test_numbers(self):
|
||||||
for typ in nums:
|
for typ in subclasses:
|
||||||
self.failUnless(repr(typ(42)).startswith(typ.__name__))
|
base = typ.__bases__[0]
|
||||||
class X(typ):
|
self.failUnless(repr(base(42)).startswith(base.__name__))
|
||||||
pass
|
self.failUnlessEqual("<X object at", repr(typ(42))[:12])
|
||||||
self.failUnlessEqual("<X object at", repr(X(42))[:12])
|
|
||||||
|
|
||||||
def test_char(self):
|
def test_char(self):
|
||||||
self.failUnlessEqual("c_char('x')", repr(c_char('x')))
|
self.failUnlessEqual("c_char('x')", repr(c_char('x')))
|
||||||
|
|
||||||
class X(c_char):
|
|
||||||
pass
|
|
||||||
self.failUnlessEqual("<X object at", repr(X('x'))[:12])
|
self.failUnlessEqual("<X object at", repr(X('x'))[:12])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue