[pypy-svn] r74933 - in pypy/branch/blackhole-improvement/pypy: annotation annotation/test rpython/test

arigo at codespeak.net arigo at codespeak.net
Sun May 30 20:51:36 CEST 2010


Author: arigo
Date: Sun May 30 20:51:34 2010
New Revision: 74933

Modified:
   pypy/branch/blackhole-improvement/pypy/annotation/description.py
   pypy/branch/blackhole-improvement/pypy/annotation/test/test_annrpython.py
   pypy/branch/blackhole-improvement/pypy/rpython/test/test_exception.py
Log:
Add negative tests, and add an explicit check to detect the bogus case.


Modified: pypy/branch/blackhole-improvement/pypy/annotation/description.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/annotation/description.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/annotation/description.py	Sun May 30 20:51:34 2010
@@ -538,9 +538,18 @@
                 try:
                     args.fixedunpack(0)
                 except ValueError:
-
                     raise Exception("default __init__ takes no argument"
                                     " (class %s)" % (self.name,))
+            elif self.pyobj is Exception:
+                # check explicitly against "raise Exception, x" where x
+                # is a low-level exception pointer
+                try:
+                    [s_arg] = args.fixedunpack(1)
+                except ValueError:
+                    pass
+                else:
+                    from pypy.annotation.model import SomePtr
+                    assert not isinstance(s_arg, SomePtr)
         else:
             # call the constructor
             args = args.prepend(s_instance)

Modified: pypy/branch/blackhole-improvement/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/annotation/test/test_annrpython.py	Sun May 30 20:51:34 2010
@@ -3283,6 +3283,17 @@
         s = a.build_types(f, [int])
         assert s.knowntype is int
 
+    def test_cannot_raise_ll_exception(self):
+        from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
+        #
+        def f():
+            e = OverflowError()
+            lle = cast_instance_to_base_ptr(e)
+            raise Exception, lle
+            # ^^^ instead, must cast back from a base ptr to an instance
+        a = self.RPythonAnnotator()
+        py.test.raises(AssertionError, a.build_types, f, [])
+
 
 def g(n):
     return [0,1,2,n]

Modified: pypy/branch/blackhole-improvement/pypy/rpython/test/test_exception.py
==============================================================================
--- pypy/branch/blackhole-improvement/pypy/rpython/test/test_exception.py	(original)
+++ pypy/branch/blackhole-improvement/pypy/rpython/test/test_exception.py	Sun May 30 20:51:34 2010
@@ -3,6 +3,7 @@
 from pypy.rpython.lltypesystem.lltype import *
 from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
 from pypy.rpython.llinterp import LLException
+from pypy.rpython.error import MissingRTypeOperation 
 
 class MyException(Exception):
     pass
@@ -125,19 +126,18 @@
 
 
 class TestLLtype(BaseTestException, LLRtypeMixin):
-    def test_raise_ll_exception(self):
+    def test_cannot_raise_ll_exception(self):
         from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
         def g():
             e = OverflowError()
             lle = cast_instance_to_base_ptr(e)
-            raise Exception, lle
+            raise lle  # instead, must cast back from a base ptr to an instance
         def f():
             try:
                 g()
             except OverflowError:
                 return 42
-        res = self.interpret(f, [])
-        assert res == 42
+        py.test.raises(MissingRTypeOperation, self.interpret, f, [])
 
 class TestOOtype(BaseTestException, OORtypeMixin):
     pass



More information about the Pypy-commit mailing list