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 selected_doc(obj, *args): |
---|
113 | ... doc = obj.__doc__.splitlines() |
---|
114 | ... return "\\n".join(["|"+doc[i] for i in args]) |
---|
115 | |
---|
116 | >>> print selected_doc(X.__init__, 0, 2, 4, 6, 8, 9, 10, 12) |
---|
117 | |C++ signature: |
---|
118 | |C++ signature: |
---|
119 | |C++ signature: |
---|
120 | |C++ signature: |
---|
121 | | |
---|
122 | |doc of init |
---|
123 | |C++ signature: |
---|
124 | |C++ signature: |
---|
125 | |
---|
126 | >>> print selected_doc(Y.__init__, 0, 1) |
---|
127 | |doc of Y init |
---|
128 | |C++ signature: |
---|
129 | |
---|
130 | >>> print selected_doc(X.bar2, 0, 2, 4, 6, 8, 9, 10) |
---|
131 | |C++ signature: |
---|
132 | |C++ signature: |
---|
133 | |C++ signature: |
---|
134 | |C++ signature: |
---|
135 | | |
---|
136 | |doc of X::bar2 |
---|
137 | |C++ signature: |
---|
138 | |
---|
139 | """ |
---|
140 | def run(args = None): |
---|
141 | import sys |
---|
142 | import doctest |
---|
143 | |
---|
144 | if args is not None: |
---|
145 | sys.argv = args |
---|
146 | return doctest.testmod(sys.modules.get(__name__)) |
---|
147 | |
---|
148 | if __name__ == '__main__': |
---|
149 | print "running..." |
---|
150 | import sys |
---|
151 | status = run()[0] |
---|
152 | if (status == 0): print "Done." |
---|
153 | sys.exit(status) |
---|