[pypy-svn] r51436 - pypy/dist/pypy/lib/app_test/ctypes

fijal at codespeak.net fijal at codespeak.net
Wed Feb 13 14:21:05 CET 2008


Author: fijal
Date: Wed Feb 13 14:21:05 2008
New Revision: 51436

Added:
   pypy/dist/pypy/lib/app_test/ctypes/support.py   (contents, props changed)
Modified:
   pypy/dist/pypy/lib/app_test/ctypes/test_functions.py
   pypy/dist/pypy/lib/app_test/ctypes/test_numbers.py
   pypy/dist/pypy/lib/app_test/ctypes/test_pointers.py
   pypy/dist/pypy/lib/app_test/ctypes/test_strings.py
   pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
Log:
Introduce some keepalive checkers


Added: pypy/dist/pypy/lib/app_test/ctypes/support.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/lib/app_test/ctypes/support.py	Wed Feb 13 14:21:05 2008
@@ -0,0 +1,20 @@
+
+class BaseCTypesTestChecker:
+    def setup_class(cls):
+        try:
+            import _rawffi
+        except ImportError:
+            pass
+        else:
+            cls.old_num = _rawffi._num_of_allocated_objects()
+    
+    def teardown_class(cls):
+        try:
+            import _rawffi
+        except ImportError:
+            pass
+        else:
+            import gc
+            gc.collect()
+            # there is one reference coming from the byref() above
+            assert _rawffi._num_of_allocated_objects() <= cls.old_num

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_functions.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_functions.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_functions.py	Wed Feb 13 14:21:05 2008
@@ -8,6 +8,7 @@
 from ctypes import *
 import sys
 import py
+from support import BaseCTypesTestChecker
 
 try:
     WINFUNCTYPE
@@ -28,7 +29,7 @@
 class RECT(Structure):
     _fields_ = [("left", c_int), ("top", c_int),
                 ("right", c_int), ("bottom", c_int)]
-class TestFunctions:
+class TestFunctions(BaseCTypesTestChecker):
 
     def test_mro(self):
         # in Python 2.3, this raises TypeError: MRO conflict among bases classes,

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_numbers.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_numbers.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_numbers.py	Wed Feb 13 14:21:05 2008
@@ -1,5 +1,6 @@
 import py
 from ctypes import *
+from support import BaseCTypesTestChecker
 import sys, struct
 
 def valid_ranges(*types):
@@ -40,25 +41,7 @@
 
 ################################################################
 
-class TestNumber:
-    def setup_class(cls):
-        try:
-            import _rawffi
-        except ImportError:
-            pass
-        else:
-            cls.old_num = _rawffi._num_of_allocated_objects()
-    
-    def teardown_class(cls):
-        try:
-            import _rawffi
-        except ImportError:
-            pass
-        else:
-            import gc
-            gc.collect()
-            # there is one reference coming from the byref() above
-            assert _rawffi._num_of_allocated_objects() <= cls.old_num
+class TestNumber(BaseCTypesTestChecker):
 
     def test_default_init(self):
         # default values are set to zero

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_pointers.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_pointers.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_pointers.py	Wed Feb 13 14:21:05 2008
@@ -1,5 +1,6 @@
 import py
 from ctypes import *
+from support import BaseCTypesTestChecker
 
 ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
                  c_long, c_ulong, c_longlong, c_ulonglong, c_double, c_float]
@@ -11,7 +12,6 @@
     mod._ctypes_test = str(conftest.sofile)
 
 class TestPointers:
-
     def test_pointer_crash(self):
 
         class A(POINTER(c_ulong)):

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_strings.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_strings.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_strings.py	Wed Feb 13 14:21:05 2008
@@ -1,8 +1,9 @@
 
 import py
 from ctypes import *
+from support import BaseCTypesTestChecker
 
-class TestStringArray:
+class TestStringArray(BaseCTypesTestChecker):
     def test_one(self):
         BUF = c_char * 4
 
@@ -53,7 +54,7 @@
 except NameError:
     pass
 else:
-    class TestWString:
+    class TestWString(BaseCTypesTestChecker):
         def test(self):
             BUF = c_wchar * 4
 

Modified: pypy/dist/pypy/lib/app_test/ctypes/test_structures.py
==============================================================================
--- pypy/dist/pypy/lib/app_test/ctypes/test_structures.py	(original)
+++ pypy/dist/pypy/lib/app_test/ctypes/test_structures.py	Wed Feb 13 14:21:05 2008
@@ -1,9 +1,10 @@
 from ctypes import *
 from struct import calcsize
+from support import BaseCTypesTestChecker
 
 import py
 
-class TestSubclasses:
+class TestSubclasses(BaseCTypesTestChecker):
     def test_subclass(self):
         class X(Structure):
             _fields_ = [("a", c_int)]
@@ -42,7 +43,7 @@
         assert Y._fields_ == [("b", c_int)]
         assert Z._fields_ == [("a", c_int)]
 
-class TestStructure:
+class TestStructure(BaseCTypesTestChecker):
     formats = {"c": c_char,
                "b": c_byte,
                "B": c_ubyte,
@@ -348,7 +349,7 @@
         assert "from_address" in dir(type(Structure))
         assert "in_dll" in dir(type(Structure))
 
-class TestPointerMember:
+class TestPointerMember:#(BaseCTypesTestChecker):
 
     def test_1(self):
         # a Structure with a POINTER field
@@ -389,7 +390,7 @@
         s.p = None
         assert s.x == 12345678
 
-class TestRecursiveStructure:
+class TestRecursiveStructure(BaseCTypesTestChecker):
     def test_contains_itself(self):
         class Recursive(Structure):
             pass
@@ -421,7 +422,7 @@
             raise AssertionError, "AttributeError not raised"
 
 
-class TestPatologicalCases:
+class TestPatologicalCases(BaseCTypesTestChecker):
     def test_structure_overloading_getattr(self):
         class X(Structure):
             _fields_ = [('x', c_int)]



More information about the Pypy-commit mailing list