Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 18a6be9

Browse files
author
Jim Fulton
committed
Added tests for sample modules.
1 parent f0e38d1 commit 18a6be9

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

Doc/ext/test.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""Test module for the noddy examples
2+
3+
Noddy 1:
4+
5+
>>> import noddy
6+
>>> n1 = noddy.Noddy()
7+
>>> n2 = noddy.Noddy()
8+
>>> del n1
9+
>>> del n2
10+
11+
12+
Noddy 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
21+
42
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
48+
2
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
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
73+
0
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
80+
81+
82+
Noddy 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
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
109+
"""
110+
111+
import os
112+
import sys
113+
from distutils.util import get_platform
114+
PLAT_SPEC = "%s-%s" % (get_platform(), sys.version[0:3])
115+
src = os.path.join("build", "lib.%s" % PLAT_SPEC)
116+
sys.path.append(src)
117+
118+
if __name__ == "__main__":
119+
import doctest, __main__
120+
doctest.testmod(__main__)
121+

0 commit comments

Comments
 (0)