[pypy-svn] r64155 - in pypy/trunk/pypy/interpreter: . test

iko at codespeak.net iko at codespeak.net
Thu Apr 16 13:49:02 CEST 2009


Author: iko
Date: Thu Apr 16 13:48:59 2009
New Revision: 64155

Modified:
   pypy/trunk/pypy/interpreter/pyopcode.py
   pypy/trunk/pypy/interpreter/test/test_pyframe.py
Log:
(iko, pedronis)

Fix tracing / finally interaction



Modified: pypy/trunk/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pyopcode.py	(original)
+++ pypy/trunk/pypy/interpreter/pyopcode.py	Thu Apr 16 13:48:59 2009
@@ -1077,7 +1077,7 @@
     def __init__(self, operr):
         self.operr = operr
     def nomoreblocks(self):
-        raise self.operr
+        raise RaiseWithExplicitTraceback(self.operr)
 
     def state_unpack_variables(self, space):
         return [self.operr.w_type, self.operr.w_value]

Modified: pypy/trunk/pypy/interpreter/test/test_pyframe.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_pyframe.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_pyframe.py	Thu Apr 16 13:48:59 2009
@@ -198,6 +198,91 @@
             except ValueError:
                 pass
 
+    def test_trace_try_finally(self):
+        import sys
+        l = []
+        def trace(frame, event, arg):
+            if event == 'exception':
+                l.append(arg)
+            return trace
+
+        def g():
+            try:
+                raise Exception
+            finally:
+                pass
+
+        def f():
+            try:
+                g()
+            except:
+                pass
+
+        sys.settrace(trace)
+        f()
+        sys.settrace(None)
+        assert len(l) == 2
+        assert issubclass(l[0][0], Exception)
+        assert issubclass(l[1][0], Exception)
+
+    def test_trace_raise_three_arg(self):
+        import sys
+        l = []
+        def trace(frame, event, arg):
+            if event == 'exception':
+                l.append(arg)
+            return trace
+
+        def g():
+            try:
+                raise Exception
+            except Exception, e:
+                import sys
+                raise Exception, e, sys.exc_info()[2]
+
+        def f():
+            try:
+                g()
+            except:
+                pass
+
+        sys.settrace(trace)
+        f()
+        sys.settrace(None)
+        assert len(l) == 2
+        assert issubclass(l[0][0], Exception)
+        assert issubclass(l[1][0], Exception)
+        
+
+    def test_trace_generator_finalisation(self):
+        # XXX expand to check more aspects
+        import sys
+        l = []
+        def trace(frame, event, arg):
+            if event == 'exception':
+                l.append(arg)
+            return trace
+
+        def g():
+            try:
+                yield True
+            finally:
+                pass
+
+        def f():
+            try:
+                gen = g()
+                gen.next()
+                gen.close()
+            except:
+                pass
+
+        sys.settrace(trace)
+        f()
+        sys.settrace(None)
+        assert len(l) == 1
+        assert issubclass(l[0][0], GeneratorExit)
+
     def test_dont_trace_on_reraise(self):
         import sys
         l = []



More information about the Pypy-commit mailing list