Changes due to added test for fileConfig contributed by Shane Hathaway.
[python.git] / Doc / ext / test.py
blob7ebf46afd1ee3c3ed793024cf961c90428229d55
1 """Test module for the noddy examples
3 Noddy 1:
5 >>> import noddy
6 >>> n1 = noddy.Noddy()
7 >>> n2 = noddy.Noddy()
8 >>> del n1
9 >>> del n2
12 Noddy 2
14 >>> import noddy2
15 >>> n1 = noddy2.Noddy('jim', 'fulton', 42)
16 >>> n1.first
17 'jim'
18 >>> n1.last
19 'fulton'
20 >>> n1.number
22 >>> n1.name()
23 'jim fulton'
24 >>> n1.first = 'will'
25 >>> n1.name()
26 'will fulton'
27 >>> n1.last = 'tell'
28 >>> n1.name()
29 'will tell'
30 >>> del n1.first
31 >>> n1.name()
32 Traceback (most recent call last):
33 ...
34 AttributeError: first
35 >>> n1.first
36 Traceback (most recent call last):
37 ...
38 AttributeError: first
39 >>> n1.first = 'drew'
40 >>> n1.first
41 'drew'
42 >>> del n1.number
43 Traceback (most recent call last):
44 ...
45 TypeError: can't delete numeric/char attribute
46 >>> n1.number=2
47 >>> n1.number
49 >>> n1.first = 42
50 >>> n1.name()
51 '42 tell'
52 >>> n2 = noddy2.Noddy()
53 >>> n2.name()
54 ' '
55 >>> n2.first
57 >>> n2.last
59 >>> del n2.first
60 >>> n2.first
61 Traceback (most recent call last):
62 ...
63 AttributeError: first
64 >>> n2.first
65 Traceback (most recent call last):
66 ...
67 AttributeError: first
68 >>> n2.name()
69 Traceback (most recent call last):
70 File "<stdin>", line 1, in ?
71 AttributeError: first
72 >>> n2.number
74 >>> n3 = noddy2.Noddy('jim', 'fulton', 'waaa')
75 Traceback (most recent call last):
76 File "<stdin>", line 1, in ?
77 TypeError: an integer is required
78 >>> del n1
79 >>> del n2
82 Noddy 3
84 >>> import noddy3
85 >>> n1 = noddy3.Noddy('jim', 'fulton', 42)
86 >>> n1 = noddy3.Noddy('jim', 'fulton', 42)
87 >>> n1.name()
88 'jim fulton'
89 >>> del n1.first
90 Traceback (most recent call last):
91 File "<stdin>", line 1, in ?
92 TypeError: Cannot delete the first attribute
93 >>> n1.first = 42
94 Traceback (most recent call last):
95 File "<stdin>", line 1, in ?
96 TypeError: The first attribute value must be a string
97 >>> n1.first = 'will'
98 >>> n1.name()
99 'will fulton'
100 >>> n2 = noddy3.Noddy()
101 >>> n2 = noddy3.Noddy()
102 >>> n2 = noddy3.Noddy()
103 >>> n3 = noddy3.Noddy('jim', 'fulton', 'waaa')
104 Traceback (most recent call last):
105 File "<stdin>", line 1, in ?
106 TypeError: an integer is required
107 >>> del n1
108 >>> del n2
110 Noddy 4
112 >>> import noddy4
113 >>> n1 = noddy4.Noddy('jim', 'fulton', 42)
114 >>> n1.first
115 'jim'
116 >>> n1.last
117 'fulton'
118 >>> n1.number
120 >>> n1.name()
121 'jim fulton'
122 >>> n1.first = 'will'
123 >>> n1.name()
124 'will fulton'
125 >>> n1.last = 'tell'
126 >>> n1.name()
127 'will tell'
128 >>> del n1.first
129 >>> n1.name()
130 Traceback (most recent call last):
132 AttributeError: first
133 >>> n1.first
134 Traceback (most recent call last):
136 AttributeError: first
137 >>> n1.first = 'drew'
138 >>> n1.first
139 'drew'
140 >>> del n1.number
141 Traceback (most recent call last):
143 TypeError: can't delete numeric/char attribute
144 >>> n1.number=2
145 >>> n1.number
147 >>> n1.first = 42
148 >>> n1.name()
149 '42 tell'
150 >>> n2 = noddy4.Noddy()
151 >>> n2 = noddy4.Noddy()
152 >>> n2 = noddy4.Noddy()
153 >>> n2 = noddy4.Noddy()
154 >>> n2.name()
156 >>> n2.first
158 >>> n2.last
160 >>> del n2.first
161 >>> n2.first
162 Traceback (most recent call last):
164 AttributeError: first
165 >>> n2.first
166 Traceback (most recent call last):
168 AttributeError: first
169 >>> n2.name()
170 Traceback (most recent call last):
171 File "<stdin>", line 1, in ?
172 AttributeError: first
173 >>> n2.number
175 >>> n3 = noddy4.Noddy('jim', 'fulton', 'waaa')
176 Traceback (most recent call last):
177 File "<stdin>", line 1, in ?
178 TypeError: an integer is required
181 Test cyclic gc(?)
183 >>> import gc
184 >>> gc.disable()
186 >>> x = []
187 >>> l = [x]
188 >>> n2.first = l
189 >>> n2.first
190 [[]]
191 >>> l.append(n2)
192 >>> del l
193 >>> del n1
194 >>> del n2
195 >>> sys.getrefcount(x)
197 >>> ignore = gc.collect()
198 >>> sys.getrefcount(x)
201 >>> gc.enable()
204 import os
205 import sys
206 from distutils.util import get_platform
207 PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
208 src = os.path.join("build", "lib.%s" % PLAT_SPEC)
209 sys.path.append(src)
211 if __name__ == "__main__":
212 import doctest, __main__
213 doctest.testmod(__main__)