[Python-checkins] r42992 - python/trunk/Lib/ctypes/test/test_checkretval.py python/trunk/Lib/ctypes/test/test_repr.py
thomas.heller
python-checkins at python.org
Mon Mar 13 11:47:03 CET 2006
Author: thomas.heller
Date: Mon Mar 13 11:47:02 2006
New Revision: 42992
Modified:
python/trunk/Lib/ctypes/test/test_checkretval.py
python/trunk/Lib/ctypes/test/test_repr.py
Log:
Plug some refcount leaks when tests are run repeatedly.
Modified: python/trunk/Lib/ctypes/test/test_checkretval.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_checkretval.py (original)
+++ python/trunk/Lib/ctypes/test/test_checkretval.py Mon Mar 13 11:47:02 2006
@@ -3,16 +3,16 @@
from ctypes import *
+class CHECKED(c_int):
+ def _check_retval_(value):
+ # Receives a CHECKED instance.
+ return str(value.value)
+ _check_retval_ = staticmethod(_check_retval_)
+
class Test(unittest.TestCase):
def test_checkretval(self):
- class CHECKED(c_int):
- def _check_retval_(value):
- # Receives a CHECKED instance.
- return str(value.value)
- _check_retval_ = staticmethod(_check_retval_)
-
import _ctypes_test
dll = cdll.load(_ctypes_test.__file__)
self.failUnlessEqual(42, dll._testfunc_p_p(42))
Modified: python/trunk/Lib/ctypes/test/test_repr.py
==============================================================================
--- python/trunk/Lib/ctypes/test/test_repr.py (original)
+++ python/trunk/Lib/ctypes/test/test_repr.py Mon Mar 13 11:47:02 2006
@@ -1,23 +1,28 @@
from ctypes import *
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_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):
def test_numbers(self):
- for typ in nums:
- self.failUnless(repr(typ(42)).startswith(typ.__name__))
- class X(typ):
- pass
- self.failUnlessEqual("<X object at", repr(X(42))[:12])
+ for typ in subclasses:
+ base = typ.__bases__[0]
+ self.failUnless(repr(base(42)).startswith(base.__name__))
+ self.failUnlessEqual("<X object at", repr(typ(42))[:12])
def test_char(self):
self.failUnlessEqual("c_char('x')", repr(c_char('x')))
-
- class X(c_char):
- pass
self.failUnlessEqual("<X object at", repr(X('x'))[:12])
if __name__ == "__main__":
More information about the Python-checkins
mailing list