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