blob: 7ebf46afd1ee3c3ed793024cf961c90428229d55 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001"""Test module for the noddy examples
2
3Noddy 1:
4
5>>> import noddy
6>>> n1 = noddy.Noddy()
7>>> n2 = noddy.Noddy()
8>>> del n1
9>>> del n2
10
11
12Noddy 2
13
14>>> import noddy2
15>>> n1 = noddy2.Noddy('jim', 'fulton', 42)
16>>> n1.first
17'jim'
18>>> n1.last
19'fulton'
20>>> n1.number
2142
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()
32Traceback (most recent call last):
33...
34AttributeError: first
35>>> n1.first
36Traceback (most recent call last):
37...
38AttributeError: first
39>>> n1.first = 'drew'
40>>> n1.first
41'drew'
42>>> del n1.number
43Traceback (most recent call last):
44...
45TypeError: can't delete numeric/char attribute
46>>> n1.number=2
47>>> n1.number
482
49>>> n1.first = 42
50>>> n1.name()
51'42 tell'
52>>> n2 = noddy2.Noddy()
53>>> n2.name()
54' '
55>>> n2.first
56''
57>>> n2.last
58''
59>>> del n2.first
60>>> n2.first
61Traceback (most recent call last):
62...
63AttributeError: first
64>>> n2.first
65Traceback (most recent call last):
66...
67AttributeError: first
68>>> n2.name()
69Traceback (most recent call last):
70 File "<stdin>", line 1, in ?
71AttributeError: first
72>>> n2.number
730
74>>> n3 = noddy2.Noddy('jim', 'fulton', 'waaa')
75Traceback (most recent call last):
76 File "<stdin>", line 1, in ?
77TypeError: an integer is required
78>>> del n1
79>>> del n2
80
81
82Noddy 3
83
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
90Traceback (most recent call last):
91 File "<stdin>", line 1, in ?
92TypeError: Cannot delete the first attribute
93>>> n1.first = 42
94Traceback (most recent call last):
95 File "<stdin>", line 1, in ?
96TypeError: 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')
104Traceback (most recent call last):
105 File "<stdin>", line 1, in ?
106TypeError: an integer is required
107>>> del n1
108>>> del n2
109
110Noddy 4
111
112>>> import noddy4
113>>> n1 = noddy4.Noddy('jim', 'fulton', 42)
114>>> n1.first
115'jim'
116>>> n1.last
117'fulton'
118>>> n1.number
11942
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()
130Traceback (most recent call last):
131...
132AttributeError: first
133>>> n1.first
134Traceback (most recent call last):
135...
136AttributeError: first
137>>> n1.first = 'drew'
138>>> n1.first
139'drew'
140>>> del n1.number
141Traceback (most recent call last):
142...
143TypeError: can't delete numeric/char attribute
144>>> n1.number=2
145>>> n1.number
1462
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()
155' '
156>>> n2.first
157''
158>>> n2.last
159''
160>>> del n2.first
161>>> n2.first
162Traceback (most recent call last):
163...
164AttributeError: first
165>>> n2.first
166Traceback (most recent call last):
167...
168AttributeError: first
169>>> n2.name()
170Traceback (most recent call last):
171 File "<stdin>", line 1, in ?
172AttributeError: first
173>>> n2.number
1740
175>>> n3 = noddy4.Noddy('jim', 'fulton', 'waaa')
176Traceback (most recent call last):
177 File "<stdin>", line 1, in ?
178TypeError: an integer is required
179
180
181Test cyclic gc(?)
182
183>>> import gc
184>>> gc.disable()
185
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)
1963
197>>> ignore = gc.collect()
198>>> sys.getrefcount(x)
1992
200
201>>> gc.enable()
202"""
203
204import os
205import sys
206from distutils.util import get_platform
207PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
208src = os.path.join("build", "lib.%s" % PLAT_SPEC)
209sys.path.append(src)
210
211if __name__ == "__main__":
212 import doctest, __main__
213 doctest.testmod(__main__)