blob: 5e09e7c9bcc86b57b8f854fe71ce343660aff339 [file] [log] [blame]
Jim Fulton18a6be92003-06-28 11:54:40 +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"""
110
111import os
112import sys
113from distutils.util import get_platform
114PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
115src = os.path.join("build", "lib.%s" % PLAT_SPEC)
116sys.path.append(src)
117
118if __name__ == "__main__":
119 import doctest, __main__
120 doctest.testmod(__main__)
121