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