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