File: test_proxy_usercreated.py

package info (click to toggle)
pypy3 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 111,848 kB
  • sloc: python: 1,291,746; ansic: 74,281; asm: 5,187; cpp: 3,017; sh: 2,533; makefile: 544; xml: 243; lisp: 45; csh: 21; awk: 4
file content (42 lines) | stat: -rw-r--r-- 1,215 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

import py
from pypy.interpreter.baseobjspace import W_Root, ObjSpace
from pypy.objspace.std.test.test_proxy_internals import AppProxy
from pypy.interpreter.typedef import TypeDef
from pypy.interpreter.gateway import interp2app
from pypy.objspace.std.transparent import register_proxyable
from pypy.conftest import option


class W_Wrapped(W_Root):
    def new(space, w_type):
        return space.wrap(W_Wrapped())

    def name(self, space):
        return space.wrap("wrapped")
    name.unwrap_spec = ['self', ObjSpace]

W_Wrapped.typedef = TypeDef(
    'Wrapped',
    __new__ = interp2app(W_Wrapped.new.im_func),
    __name__ = interp2app(W_Wrapped.name),
)


class AppTestProxyNewtype(AppProxy):
    def setup_class(cls):
        if option.runappdirect:
            py.test.skip("Impossible to run on appdirect")
        AppProxy.setup_class.im_func(cls)
        cls.w_wrapped = cls.space.wrap(W_Wrapped())
        register_proxyable(cls.space, W_Wrapped)

    def test_one(self):
        x = type(self.wrapped)()
        from __pypy__ import tproxy

        def f(name, *args, **kwds):
            return getattr(x, name)(*args, **kwds)

        t = tproxy(type(x), f)
        assert t.__name__ == x.__name__