[pypy-svn] r64829 - pypy/branch/pyjitpl5/pypy/translator/c/test

arigo at codespeak.net arigo at codespeak.net
Wed Apr 29 19:19:42 CEST 2009


Author: arigo
Date: Wed Apr 29 19:19:39 2009
New Revision: 64829

Modified:
   pypy/branch/pyjitpl5/pypy/translator/c/test/test_exception.py
Log:
Copy test_reraise_exception (which passes) from
translator/oosupport/test_template/exception.py.


Modified: pypy/branch/pyjitpl5/pypy/translator/c/test/test_exception.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/translator/c/test/test_exception.py	(original)
+++ pypy/branch/pyjitpl5/pypy/translator/c/test/test_exception.py	Wed Apr 29 19:19:39 2009
@@ -1,9 +1,11 @@
 import py
 import sys
 from pypy.translator.c.test import test_typed
+from pypy.translator.c.test import test_backendoptimized
 from pypy.rpython.lltypesystem import lltype
 
 getcompiled = test_typed.TestTypedTestCase().getcompiled
+getcompiledopt = test_backendoptimized.TestTypedOptimizedTestCase().getcompiled
 
 
 class TestException(Exception):
@@ -132,7 +134,6 @@
     finally:
         restore_magic(saved)
 
-
 def no_magic():
     import __builtin__
     try:
@@ -144,3 +145,35 @@
 def restore_magic(saved):
     if saved:
         py.magic.invoke(assertion=True)
+
+
+def test_reraise_exception():
+    class A(Exception):
+        pass
+
+    def raise_something(n):
+        if n > 10:
+            raise A
+        else:
+            raise Exception
+
+    def foo(n):
+        try:
+            raise_something(n)
+        except A:
+            raise     # go through
+        except Exception, e:
+            return 100
+        return -1
+
+    def fn(n):
+        try:
+            return foo(n)
+        except A:
+            return 42
+
+    f1 = getcompiledopt(fn, [int])
+    res = f1(100)
+    assert res == 42
+    res = f1(0)
+    assert res == 100



More information about the Pypy-commit mailing list