Remove the slightly broken test_leaks.py.

Change test_functions.py so that it can be run multiple time without
failing: Assign a restype to the function in test_intresult, and move
the definition of class POINT to module level so that no new class is
created each time the test is run.
This commit is contained in:
Thomas Heller 2006-03-13 07:33:38 +00:00
parent b1386772b5
commit 6058aa40d2
2 changed files with 4 additions and 91 deletions

View File

@ -19,6 +19,9 @@ dll = cdll.load(_ctypes_test.__file__)
if sys.platform == "win32":
windll = windll.load(_ctypes_test.__file__)
class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
class FunctionTestCase(unittest.TestCase):
def test_mro(self):
@ -91,6 +94,7 @@ class FunctionTestCase(unittest.TestCase):
def test_intresult(self):
f = dll._testfunc_i_bhilfd
f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double]
f.restype = c_int
result = f(1, 2, 3, 4, 5.0, 6.0)
self.failUnlessEqual(result, 21)
self.failUnlessEqual(type(result), int)
@ -299,9 +303,6 @@ class FunctionTestCase(unittest.TestCase):
def test_byval(self):
class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
# without prototype
ptin = POINT(1, 2)
ptout = POINT()

View File

@ -1,88 +0,0 @@
import unittest, sys, gc
from ctypes import *
from ctypes import _pointer_type_cache
class LeakTestCase(unittest.TestCase):
################
def make_noncyclic_structures(self, repeat):
for i in xrange(repeat):
class POINT(Structure):
_fields_ = [("x", c_int), ("y", c_int)]
class RECT(Structure):
_fields_ = [("ul", POINT),
("br", POINT)]
if hasattr(sys, "gettotalrefcount"):
def test_no_cycles_refcount(self):
last_refcount = 0
for x in xrange(20):
self.make_noncyclic_structures(1000)
while gc.collect():
pass
total_refcount = sys.gettotalrefcount()
if last_refcount >= total_refcount:
return # test passed
last_refcount = total_refcount
self.fail("leaking refcounts")
def test_no_cycles_objcount(self):
# not correct - gc.get_objects() returns only thos objects
# that the garbage collector tracks. Correct would be to use
# sys.getobjects(), but this is only available in debug build.
last_objcount = 0
for x in xrange(20):
self.make_noncyclic_structures(1000)
while gc.collect():
pass
total_objcount = gc.get_objects()
if last_objcount >= total_objcount:
return # test passed
last_objcount = total_objcount
self.fail("leaking objects")
################
def make_cyclic_structures(self, repeat):
for i in xrange(repeat):
PLIST = POINTER("LIST")
class LIST(Structure):
_fields_ = [("pnext", PLIST)]
SetPointerType(PLIST, LIST)
del _pointer_type_cache[LIST] # XXX should this be a weakkeydict?
if hasattr(sys, "gettotalrefcount"):
def test_cycles_refcount(self):
last_refcount = 0
for x in xrange(5):
self.make_cyclic_structures(1000)
while gc.collect():
pass
total_refcount = sys.gettotalrefcount()
if last_refcount >= total_refcount:
return
last_refcount = total_refcount
self.fail("leaking refcounts")
else:
def test_cycles_objcount(self):
# not correct - gc.get_objects() returns only thos objects
# that the garbage collector tracks. Correct would be to use
# sys.getobjects(), but this is only available in debug build.
last_objcount = 0
for x in xrange(8):
self.make_cyclic_structures(1000)
while gc.collect():
pass
total_objcount = len(gc.get_objects())
if last_objcount >= total_objcount:
return
last_objcount = total_objcount
self.fail("leaking objects")
if __name__ == "__main__":
unittest.main()