Debian Codegraph @

pypy/objspace/std/test/test_proxy_object.py

raw symbols SCIP
1
2 """ test proxy object
3 """
4
5 from pypy.objspace.std.test.test_proxy import AppProxyBasic
6
7 class AppTestProxyNoDict(AppProxyBasic):
8 def setup_method(self, meth):
9 super(AppTestProxyNoDict, self).setup_method(meth)
10 self.w_A = self.space.appexec([], """():
11 class A(object):
12 __slots__ = []
13 return A
14 """)
15 self.w_proxy = self.space.appexec([], """():
16 from __pypy__ import tproxy
17 return tproxy
18 """)
19
20 def test_write_dict(self):
21 c = self.Controller(self.A())
22 obj = self.proxy(self.A, c.perform)
23 raises(AttributeError, "obj.__dict__ = {}")
24
25 class AppTestProxyObj(AppProxyBasic):
26 def setup_method(self, meth):
27 super(AppTestProxyObj, self).setup_method(meth)
28 self.w_A = self.space.appexec([], """():
29 class A(object):
30 pass
31 return A
32 """)
33
34 def test_simple_obj(self):
35 class AT(self.A):
36 pass
37
38 c = self.Controller(self.A())
39 obj = self.proxy(AT, c.perform)
40
41 assert type(obj) is AT
42 assert obj.__class__ is AT
43
44 def test__class__override(self):
45 c = self.Controller(self.A())
46 obj = self.proxy(self.A, c.perform)
47
48 raises(TypeError, "obj.__class__ = self.A")
49
50 def test_attribute_access(self):
51 a = self.A()
52 a.x = 3
53 c = self.Controller(a)
54 obj = self.proxy(self.A, c.perform)
55
56 assert obj.x == 3
57
58 def test_nonexistant_attribuite_access(self):
59 c = self.Controller(self.A())
60 obj = self.proxy(self.A, c.perform)
61 raises(AttributeError, "obj.x")
62
63 def test_setattr(self):
64 a = self.A()
65 c = self.Controller(a)
66 obj = self.proxy(self.A, c.perform)
67 obj.x = 1
68 assert obj.x == 1
69 assert a.x == 1
70
71 def test_delattr(self):
72 a = self.A()
73 a.f = 3
74 c = self.Controller(a)
75 obj = self.proxy(self.A, c.perform)
76 del obj.f
77 raises(AttributeError, "obj.f")
78
79 def test__dict__(self):
80 a = self.A()
81 a.x = 3
82 c = self.Controller(a)
83 obj = self.proxy(self.A, c.perform)
84 assert 'x' in obj.__dict__
85
86 def test_set__dict__(self):
87 a = self.A()
88 c = self.Controller(a)
89 obj = self.proxy(self.A, c.perform)
90 obj.__dict__ = {'x':3}
91 assert obj.x == 3
92 assert obj.__dict__.keys() == set(['x'])
93
94 def test_repr(self):
95 a = self.A()
96 c = self.Controller(a)
97 obj = self.proxy(self.A, c.perform)
98 assert repr(obj)[:6] == repr(a)[:6]