Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/defaults.py @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.1 KB
Line 
1# Copyright David Abrahams 2004. Distributed under the Boost
2# Software License, Version 1.0. (See accompanying
3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4"""
5# Use builtin True/False when available:
6>>> try:
7...     assert(True == 1)
8... except:
9...     True = 1
10...     False = 0
11
12>>> from defaults_ext import *
13>>> bar(1)
14'int(1); char(D); string(default); double(0.0); '
15
16>>> bar(2, 'X')
17'int(2); char(X); string(default); double(0.0); '
18
19>>> bar(3, 'Y', "Hello World")
20'int(3); char(Y); string(Hello World); double(0.0); '
21
22>>> bar(4, 'Z', "Hi There", 3.3)
23'int(4); char(Z); string(Hi There); double(3.3); '
24
25>>> foo(1)
26'int(1); char(D); string(default); double(0.0); '
27
28>>> foo(2, 'X')
29'int(2); char(X); string(default); double(0.0); '
30
31>>> foo(3, 'Y', "Hello World")
32'int(3); char(Y); string(Hello World); double(0.0); '
33
34>>> foo(4, 'Z', "Hi There", 3.3)
35'int(4); char(Z); string(Hi There); double(3.3); '
36
37>>> x = X()
38>>> x.bar(1)
39'int(1); char(D); string(default); double(0.0); '
40
41>>> x.bar(2, 'X')
42'int(2); char(X); string(default); double(0.0); '
43
44>>> x.bar(3, 'Y', "Hello World")
45'int(3); char(Y); string(Hello World); double(0.0); '
46
47>>> x.bar(4, 'Z', "Hi There", 3.3)
48'int(4); char(Z); string(Hi There); double(3.3); '
49
50>>> x.foo(5)
51'int(5); bool(0); '
52
53>>> x.foo(6, 0)
54'int(6); bool(0); '
55
56>>> x.foo(7, 1)
57'int(7); bool(1); '
58
59>>> x.foo("A")
60'string(A); bool(0); '
61
62>>> x.foo("B", False)
63'string(B); bool(0); '
64
65>>> x.foo("C", True)
66'string(C); bool(1); '
67
68>>> x.foo([0,1,2], [2,3,4])
69'list([0, 1, 2]); list([2, 3, 4]); bool(0); '
70
71>>> x.foo([0,1,2], [2,3,4], False)
72'list([0, 1, 2]); list([2, 3, 4]); bool(0); '
73
74>>> x.foo([0,1,2], [2,3,4], True)
75'list([0, 1, 2]); list([2, 3, 4]); bool(1); '
76
77>>> x = X(1)
78>>> x.get_state()
79'int(1); char(D); string(constructor); double(0.0); '
80
81>>> x = X(1, 'X')
82>>> x.get_state()
83'int(1); char(X); string(constructor); double(0.0); '
84
85>>> x = X(1, 'X', "Yabadabadoo")
86>>> x.get_state()
87'int(1); char(X); string(Yabadabadoo); double(0.0); '
88
89>>> x = X(1, 'X', "Phoenix", 3.65)
90>>> x.get_state()
91'int(1); char(X); string(Phoenix); double(3.65); '
92
93>>> x.bar2().get_state()
94'int(0); char(D); string(default); double(0.0); '
95
96>>> x.bar2(1).get_state()
97'int(1); char(D); string(default); double(0.0); '
98
99>>> x.bar2(1, 'K').get_state()
100'int(1); char(K); string(default); double(0.0); '
101
102>>> x.bar2(1, 'K', "Kim").get_state()
103'int(1); char(K); string(Kim); double(0.0); '
104
105>>> x.bar2(1, 'K', "Kim", 9.9).get_state()
106'int(1); char(K); string(Kim); double(9.9); '
107
108>>> x = X("Phoenix", 1)
109>>> x.get_state()
110'Got exactly two arguments from constructor: string(Phoenix); bool(1); '
111
112>>> def printdoc(x):
113...     print x.__doc__
114
115>>> printdoc(X.__init__)
116doc of init
117
118>>> printdoc(Y.__init__)
119doc of Y init
120
121>>> printdoc(X.bar2)
122doc of X::bar2
123
124"""
125def run(args = None):
126    import sys
127    import doctest
128
129    if args is not None:
130        sys.argv = args
131    return doctest.testmod(sys.modules.get(__name__))
132
133if __name__ == '__main__':
134    print "running..."
135    import sys
136    status = run()[0]
137    if (status == 0): print "Done."
138    sys.exit(status)
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
Note: See TracBrowser for help on using the repository browser.