[pypy-svn] r34203 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Nov 4 18:21:30 CET 2006
Author: fijal
Date: Sat Nov 4 18:21:29 2006
New Revision: 34203
Modified:
pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py
pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py
pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
Log:
(samuele, fijal) - Test + PyFrame & PyTraceback
Modified: pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py (original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/proxyobject.py Sat Nov 4 18:21:29 2006
@@ -86,6 +86,10 @@
from pypy.interpreter.pytraceback import PyTraceback
typedef = PyTraceback.typedef
+class W_TransparentFrame(W_Transparent):
+ from pypy.interpreter.pyframe import PyFrame
+ typedef = PyFrame.typedef
+
class W_TransparentList(W_TransparentObject):
from pypy.objspace.std.listobject import W_ListObject as original
from pypy.objspace.std.listtype import list_typedef as typedef
Modified: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py (original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_internals.py Sat Nov 4 18:21:29 2006
@@ -39,3 +39,58 @@
raises(ZeroDivisionError, "raise e[0], self.get_proxy(e[1]), tb")
import traceback
assert len(traceback.format_tb(tb)) == 1
+
+ def test_simple_frame(self):
+ import sys
+ frame = sys._getframe(0)
+ fp = self.get_proxy(frame)
+ assert fp.f_locals == frame.f_locals
+
+class AppTestProxyTracebackController(object):
+ def test_controller(self):
+ import types
+ import sys
+ import traceback
+
+ def get_proxy(f):
+ return proxy(type(f), Controller(f).perform)
+
+ class FakeTb(object):
+ def __init__(self, tb):
+ self.tb_lasti = tb.tb_lasti
+ self.tb_lineno = tb.tb_lineno
+ if tb.tb_next:
+ self.tb_next = FakeTb(tb.tb_next)
+ else:
+ self.tb_next = None
+ self.tb_frame = get_proxy(tb.tb_frame)
+
+ class Controller(object):
+ def __init__(self, tb):
+ if isinstance(tb, types.TracebackType):
+ self.obj = FakeTb(tb)
+ else:
+ self.obj = tb
+
+ def perform(self, name, *args, **kwargs):
+ return getattr(self.obj, name)(*args, **kwargs)
+
+ def f():
+ 1/0
+
+ def g():
+ f()
+
+ try:
+ g()
+ except:
+ e = sys.exc_info()
+
+ last_tb = e[2]
+ tb = get_proxy(e[2])
+ try:
+ raise e[0], e[1], tb
+ except:
+ e = sys.exc_info()
+
+ assert traceback.format_tb(last_tb) == traceback.format_tb(e[2])
Modified: pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py (original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py Sat Nov 4 18:21:29 2006
@@ -9,7 +9,7 @@
from pypy.objspace.std.typeobject import W_TypeObject
def proxy(space, w_type, w_controller):
- from pypy.interpreter.typedef import Function, PyTraceback
+ from pypy.interpreter.typedef import Function, PyTraceback, PyFrame
if not space.is_true(space.callable(w_controller)):
raise OperationError(space.w_TypeError, space.wrap("controller should be function"))
@@ -23,6 +23,8 @@
return W_TransparentFunction(space, w_type, w_controller)
if space.is_true(space.issubtype(w_type, space.gettypeobject(PyTraceback.typedef))):
return W_TransparentTraceback(space, w_type, w_controller)
+ if space.is_true(space.issubtype(w_type, space.gettypeobject(PyFrame.typedef))):
+ return W_TransparentFrame(space, w_type, w_controller)
if w_type.instancetypedef is space.w_object.instancetypedef:
return W_Transparent(space, w_type, w_controller)
else:
More information about the Pypy-commit
mailing list