| 1 | |
| 2 | import py |
| 3 | from pypy.interpreter.baseobjspace import W_Root, ObjSpace |
| 4 | from pypy.objspace.std.test.test_proxy_internals import AppProxy |
| 5 | from pypy.interpreter.typedef import TypeDef |
| 6 | from pypy.interpreter.gateway import interp2app |
| 7 | from pypy.objspace.std.transparent import register_proxyable |
| 8 | from pypy.conftest import option |
| 9 | |
| 10 | |
| 11 | class W_Wrapped(W_Root): |
| 12 | def new(space, w_type): |
| 13 | return space.wrap(W_Wrapped()) |
| 14 | |
| 15 | def name(self, space): |
| 16 | return space.wrap("wrapped") |
| 17 | name.unwrap_spec = ['self', ObjSpace] |
| 18 | |
| 19 | W_Wrapped.typedef = TypeDef( |
| 20 | 'Wrapped', |
| 21 | __new__ = interp2app(W_Wrapped.new.im_func), |
| 22 | __name__ = interp2app(W_Wrapped.name), |
| 23 | ) |
| 24 | |
| 25 | |
| 26 | class AppTestProxyNewtype(AppProxy): |
| 27 | def setup_class(cls): |
| 28 | if option.runappdirect: |
| 29 | py.test.skip("Impossible to run on appdirect") |
| 30 | AppProxy.setup_class.im_func(cls) |
| 31 | cls.w_wrapped = cls.space.wrap(W_Wrapped()) |
| 32 | register_proxyable(cls.space, W_Wrapped) |
| 33 | |
| 34 | def test_one(self): |
| 35 | x = type(self.wrapped)() |
| 36 | from __pypy__ import tproxy |
| 37 | |
| 38 | def f(name, *args, **kwds): |
| 39 | return getattr(x, name)(*args, **kwds) |
| 40 | |
| 41 | t = tproxy(type(x), f) |
| 42 | assert t.__name__ == x.__name__ |