blob: f8b471e12088e60e8f21079890e1ee4ea2bf2c62 [file] [log] [blame]
Barry Warsaw4a420a02001-01-15 20:30:15 +00001from test_support import verbose, TestFailed
2
3class F:
4 def a(self):
5 pass
6
7def b():
8 'my docstring'
9 pass
10
11# setting attributes on functions
12try:
13 b.publish
14except AttributeError:
15 pass
16else:
17 raise TestFailed, 'expected AttributeError'
18
19b.publish = 1
20if b.publish <> 1:
21 raise TestFailed, 'function attribute not set to expected value'
22
23docstring = 'its docstring'
24b.__doc__ = docstring
25if b.__doc__ <> docstring:
26 raise TestFailed, 'problem with setting __doc__ attribute'
27
28if 'publish' not in dir(b):
29 raise TestFailed, 'attribute not in dir()'
30
31f1 = F()
32f2 = F()
33
34try:
35 F.a.publish
36except AttributeError:
37 pass
38else:
39 raise TestFailed, 'expected AttributeError'
40
41try:
42 f1.a.publish
43except AttributeError:
44 pass
45else:
46 raise TestFailed, 'expected AttributeError'
47
48
49F.a.publish = 1
50if F.a.publish <> 1:
51 raise TestFailed, 'unbound method attribute not set to expected value'
52
53if f1.a.publish <> 1:
54 raise TestFailed, 'bound method attribute access did not work'
55
56if f2.a.publish <> 1:
57 raise TestFailed, 'bound method attribute access did not work'
58
59if 'publish' not in dir(F.a):
60 raise TestFailed, 'attribute not in dir()'
61
62try:
63 f1.a.publish = 0
64except TypeError:
65 pass
66else:
67 raise TestFailed, 'expected TypeError'
68
69F.a.myclass = F
70f1.a.myclass
71f2.a.myclass
72f1.a.myclass
73F.a.myclass
74
75if f1.a.myclass is not f2.a.myclass or \
76 f1.a.myclass is not F.a.myclass:
77 raise TestFailed, 'attributes were not the same'
78
79# try setting __dict__
80try:
81 F.a.__dict__ = (1, 2, 3)
82except TypeError:
83 pass
84else:
85 raise TestFailed, 'expected TypeError'
86
87F.a.__dict__ = {'one': 11, 'two': 22, 'three': 33}
88if f1.a.two <> 22:
89 raise TestFailed, 'setting __dict__'
90
91from UserDict import UserDict
92d = UserDict({'four': 44, 'five': 55})
93
94try:
95 F.a.__dict__ = d
96except TypeError:
97 pass
98else:
99 raise TestFailed
100
101if f2.a.one <> f1.a.one <> F.a.one <> 11:
102 raise TestFailed