1
2
3
4
5
6
7
8
9
10
11
12
13
15 """
16 An object that takes a hashmap and uses it for the attributes on
17 the object. Setting attributes is ignored. Retrieving an
18 unknown attribute returns an empty MockObject. The key 'return__' is
19 special in that its corresponding value will be returned if the object
20 is called as a function.
21
22 >>> a=MockObject(b='c')
23 >>> a.b
24 'c'
25 >>> a.d
26 {}
27 >>> a.d.e
28 {}
29 >>> x=MockObject(return__=5)
30 >>> y=MockObject(z=x)
31 >>> y.z()
32 5
33 """
35 return self.attrs.get( 'return__', None )
36
38 self.attrs = kw.copy()
39
41 if item == 'attrs':
42 return self.__dict__['attrs']
43
44 try:
45 return self.attrs[item]
46 except KeyError:
47 return MockObject()
48
50 return str(self.attrs)
51
54