[pypy-svn] r48874 - in pypy/branch/new-genc-tests-wrapper/pypy/translator: c c/test llsupport

cfbolz at codespeak.net cfbolz at codespeak.net
Tue Nov 20 20:48:40 CET 2007


Author: cfbolz
Date: Tue Nov 20 20:48:40 2007
New Revision: 48874

Added:
   pypy/branch/new-genc-tests-wrapper/pypy/translator/c/test/test_modwrapper.py   (contents, props changed)
Modified:
   pypy/branch/new-genc-tests-wrapper/pypy/translator/c/gc.py
   pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
Log:
(cfbolz, rxe): start writing genc tests for the modwrapper


Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/c/gc.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/c/gc.py	(original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/c/gc.py	Tue Nov 20 20:48:40 2007
@@ -313,7 +313,7 @@
         return '%s = %s; /* for moving GCs */' % (args[1], args[0])
 
     def common_gcheader_definition(self):
-        return defnode.db.gctransformer.gc_fields()
+        return self.db.gctransformer.gc_fields()
 
     def common_gcheader_initdata(self, defnode):
         o = top_container(defnode.obj)

Added: pypy/branch/new-genc-tests-wrapper/pypy/translator/c/test/test_modwrapper.py
==============================================================================
--- (empty file)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/c/test/test_modwrapper.py	Tue Nov 20 20:48:40 2007
@@ -0,0 +1,104 @@
+import py
+from pypy.translator.c.test.test_typed import CompilationTestCase
+
+class WrapperTests(object):
+    def test_return_none(self):
+        def fn():
+            return None
+        fn = self.getcompiled(fn, [])
+        assert fn() is None
+
+    def test_return_int(self):
+        def fn():
+            return 1
+        fn = self.getcompiled(fn, [])
+        assert fn() == 1
+
+    def test_return_float(self):
+        def fn():
+            return 42.1
+        fn = self.getcompiled(fn, [])
+        assert fn() == 42.1
+
+    def test_return_true(self):
+        def fn():
+            return True
+        fn = self.getcompiled(fn, [])
+        assert fn()
+
+    def test_return_string(self):
+        def fn():
+            return "hello!"
+        fn = self.getcompiled(fn, [])
+        assert fn() == "hello!"
+
+    def test_raises_builtin_exception(self):
+        def fn():
+            raise ValueError
+        fn = self.getcompiled(fn, [])
+        py.test.raises(ValueError, fn)
+
+    def test_raises_custom_exception(self):
+        from pypy.translator.llsupport import modwrapper
+        class MyException(Exception):
+            pass
+        def fn():
+            raise MyException
+        fn = self.getcompiled(fn, [])
+        excinfo = py.test.raises(modwrapper.ExceptionWrapper, fn)
+        assert excinfo.value.class_name == "MyException"
+
+    def test_return_list_of_strings(self):
+        def f():
+            return ['abc', 'def']
+        fn = self.getcompiled(f, [])
+        assert fn() == ['abc', 'def']
+
+    def test_return_list_of_bools(self):
+        def fn():
+            return [True, True, False]
+        fn = self.getcompiled(fn, [])
+        assert fn() == [True, True, False]
+
+    def test_return_tuple_of_list_of_strings(self):
+        def fn():
+            return ['abc', 'def'],  ['abc', 'def']
+        fn = self.getcompiled(fn, [])
+        assert fn() == (['abc', 'def'],  ['abc', 'def']) 
+
+    def test_argument_1int(self):
+        def fn(x):
+            return x + 42
+        fn = self.getcompiled(fn, [int])
+        assert fn(42) == 84
+        assert fn(2) == 44
+
+    def test_argument_2int(self):
+        def fn(x, y):
+            return x + 42 * y
+        fn = self.getcompiled(fn, [int, int])
+        assert fn(42, 0) == 42
+        assert fn(2, 1) == 44
+        assert fn(6, 2) == 90
+
+
+
+class TestWrapperRefcounting(CompilationTestCase, WrapperTests):
+    pass
+
+from pypy.translator.c.test.test_boehm import AbstractGCTestClass
+
+class TestWrapperMarknSweep(AbstractGCTestClass, WrapperTests):
+    gcpolicy = "marksweep"
+
+
+class TestWrapperBoehm(AbstractGCTestClass, WrapperTests):
+    gcpolicy = "boehm"
+
+
+class TestWrapperSemispace(AbstractGCTestClass, WrapperTests):
+    gcpolicy = "semispace"
+
+
+class TestWrapperGeneration(AbstractGCTestClass, WrapperTests):
+    gcpolicy = "generation"

Modified: pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py
==============================================================================
--- pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py	(original)
+++ pypy/branch/new-genc-tests-wrapper/pypy/translator/llsupport/modwrapper.py	Tue Nov 20 20:48:40 2007
@@ -3,6 +3,7 @@
 import py
 import ctypes
 from pypy.rpython.lltypesystem import lltype 
+from pypy.rpython.lltypesystem import llmemory
 from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
 from pypy.rpython.lltypesystem.rstr import STR
 
@@ -156,11 +157,12 @@
                  lltype.SingleFloat: "ctypes.c_float",
                  lltype.Float: "ctypes.c_double",
                  lltype.Char: "ctypes.c_char",
-                 lltype.Signed: "ctypes.c_int",
-                 lltype.Unsigned: "ctypes.c_uint",
+                 lltype.Signed: "ctypes.c_long",
+                 lltype.Unsigned: "ctypes.c_ulong",
                  lltype.SignedLongLong: "ctypes.c_longlong",
                  lltype.UnsignedLongLong: "ctypes.c_ulonglong",
                  lltype.Void: None,
+                 llmemory.Address: "ctypes.c_long",
                  lltype.UniChar: "ctypes.c_uint",
                  }
 
@@ -302,9 +304,9 @@
             "r_ulonglong": r_ulonglong,
             }
         if t == "exceptiontypename":
-            exc_class = getattr(exceptions, v)
+            exc_class = getattr(exceptions, v, None)
             if exc_class is None:
-                exc_class = ExceptionWrapper(v)
+                raise ExceptionWrapper(v)
             raise exc_class()
         if t == "tuple":
             return StructTuple([unwrap(element) for element in v])



More information about the Pypy-commit mailing list