diff options
author | Thomas Heller <theller@ctypes.org> | 2006-03-13 07:33:38 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2006-03-13 07:33:38 (GMT) |
commit | 6058aa40d288d8cdd93dddfe9c660450f598b3ae (patch) | |
tree | 74e2bca66e195bbb3cbadebe4d581035db2ada23 | |
parent | b1386772b5864f18bde618f76f4291986a48ed8c (diff) | |
download | cpython-6058aa40d288d8cdd93dddfe9c660450f598b3ae.zip cpython-6058aa40d288d8cdd93dddfe9c660450f598b3ae.tar.gz cpython-6058aa40d288d8cdd93dddfe9c660450f598b3ae.tar.bz2 |
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.
-rw-r--r-- | Lib/ctypes/test/test_functions.py | 7 | ||||
-rw-r--r-- | Lib/ctypes/test/test_leaks.py | 88 |
2 files changed, 4 insertions, 91 deletions
diff --git a/Lib/ctypes/test/test_functions.py b/Lib/ctypes/test/test_functions.py index 435f510..ada9def 100644 --- a/Lib/ctypes/test/test_functions.py +++ b/Lib/ctypes/test/test_functions.py @@ -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 index c1a44bb..0000000 --- a/Lib/ctypes/test/test_leaks.py +++ /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() |