]> granicus.if.org Git - python/commitdiff
Remove the slightly broken test_leaks.py.
authorThomas Heller <theller@ctypes.org>
Mon, 13 Mar 2006 07:33:38 +0000 (07:33 +0000)
committerThomas Heller <theller@ctypes.org>
Mon, 13 Mar 2006 07:33:38 +0000 (07:33 +0000)
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.

Lib/ctypes/test/test_functions.py
Lib/ctypes/test/test_leaks.py [deleted file]

index 435f510e29b2fc317fb977384b3132301392219e..ada9def280da4ed3ba9e5ef5e1fa5ee4d8a4a48f 100644 (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()
diff --git a/Lib/ctypes/test/test_leaks.py b/Lib/ctypes/test/test_leaks.py
deleted file mode 100644 (file)
index c1a44bb..0000000
+++ /dev/null
@@ -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()