[29] | 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 | >>> from args_ext import * |
---|
| 6 | |
---|
| 7 | >>> raw(3, 4, foo = 'bar', baz = 42) |
---|
| 8 | ((3, 4), {'foo': 'bar', 'baz': 42}) |
---|
| 9 | |
---|
| 10 | Prove that we can handle empty keywords and non-keywords |
---|
| 11 | |
---|
| 12 | >>> raw(3, 4) |
---|
| 13 | ((3, 4), {}) |
---|
| 14 | |
---|
| 15 | >>> raw(foo = 'bar') |
---|
| 16 | ((), {'foo': 'bar'}) |
---|
| 17 | |
---|
| 18 | >>> f(x= 1, y = 3, z = 'hello') |
---|
| 19 | (1, 3.0, 'hello') |
---|
| 20 | |
---|
| 21 | >>> f(z = 'hello', x = 3, y = 2.5) |
---|
| 22 | (3, 2.5, 'hello') |
---|
| 23 | |
---|
| 24 | >>> f(1, z = 'hi', y = 3) |
---|
| 25 | (1, 3.0, 'hi') |
---|
| 26 | |
---|
| 27 | >>> try: f(1, 2, 'hello', bar = 'baz') |
---|
| 28 | ... except TypeError: pass |
---|
| 29 | ... else: print 'expected an exception: unknown keyword' |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | Exercise the functions using default stubs |
---|
| 33 | |
---|
| 34 | >>> f1(z = 'nix', y = .125, x = 2) |
---|
| 35 | (2, 0.125, 'nix') |
---|
| 36 | >>> f1(y = .125, x = 2) |
---|
| 37 | (2, 0.125, 'wow') |
---|
| 38 | >>> f1(x = 2) |
---|
| 39 | (2, 4.25, 'wow') |
---|
| 40 | >>> f1() |
---|
| 41 | (1, 4.25, 'wow') |
---|
| 42 | |
---|
| 43 | >>> f2(z = 'nix', y = .125, x = 2) |
---|
| 44 | (2, 0.125, 'nix') |
---|
| 45 | >>> f2(y = .125, x = 2) |
---|
| 46 | (2, 0.125, 'wow') |
---|
| 47 | >>> f2(x = 2) |
---|
| 48 | (2, 4.25, 'wow') |
---|
| 49 | >>> f2() |
---|
| 50 | (1, 4.25, 'wow') |
---|
| 51 | |
---|
| 52 | >>> f3(z = 'nix', y = .125, x = 2) |
---|
| 53 | (2, 0.125, 'nix') |
---|
| 54 | >>> f3(y = .125, x = 2) |
---|
| 55 | (2, 0.125, 'wow') |
---|
| 56 | >>> f3(x = 2) |
---|
| 57 | (2, 4.25, 'wow') |
---|
| 58 | >>> f3() |
---|
| 59 | (1, 4.25, 'wow') |
---|
| 60 | |
---|
| 61 | Member function tests |
---|
| 62 | |
---|
| 63 | >>> q = X() |
---|
| 64 | >>> q.f(x= 1, y = 3, z = 'hello') |
---|
| 65 | (1, 3.0, 'hello') |
---|
| 66 | |
---|
| 67 | >>> q.f(z = 'hello', x = 3, y = 2.5) |
---|
| 68 | (3, 2.5, 'hello') |
---|
| 69 | |
---|
| 70 | >>> q.f(1, z = 'hi', y = 3) |
---|
| 71 | (1, 3.0, 'hi') |
---|
| 72 | |
---|
| 73 | >>> try: q.f(1, 2, 'hello', bar = 'baz') |
---|
| 74 | ... except TypeError: pass |
---|
| 75 | ... else: print 'expected an exception: unknown keyword' |
---|
| 76 | |
---|
| 77 | Exercise member functions using default stubs |
---|
| 78 | |
---|
| 79 | >>> q.f1(z = 'nix', y = .125, x = 2) |
---|
| 80 | (2, 0.125, 'nix') |
---|
| 81 | >>> q.f1(y = .125, x = 2) |
---|
| 82 | (2, 0.125, 'wow') |
---|
| 83 | >>> q.f1(x = 2) |
---|
| 84 | (2, 4.25, 'wow') |
---|
| 85 | >>> q.f1() |
---|
| 86 | (1, 4.25, 'wow') |
---|
| 87 | |
---|
| 88 | >>> X.f.__doc__.splitlines()[:2] |
---|
| 89 | ["This is X.f's docstring", 'C++ signature:'] |
---|
| 90 | |
---|
| 91 | >>> xfuncs = (X.inner0, X.inner1, X.inner2, X.inner3, X.inner4, X.inner5) |
---|
| 92 | >>> for f in xfuncs: |
---|
| 93 | ... print f(q,1).value(), |
---|
| 94 | ... print f(q, n = 1).value(), |
---|
| 95 | ... print f(q, n = 0).value(), |
---|
| 96 | ... print f.__doc__.splitlines()[:2] |
---|
| 97 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 98 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 99 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 100 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 101 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 102 | 1 1 0 ['docstring', 'C++ signature:'] |
---|
| 103 | |
---|
| 104 | >>> x = X(a1 = 44, a0 = 22) |
---|
| 105 | >>> x.inner0(0).value() |
---|
| 106 | 22 |
---|
| 107 | >>> x.inner0(1).value() |
---|
| 108 | 44 |
---|
| 109 | |
---|
| 110 | >>> x = X(a0 = 7) |
---|
| 111 | >>> x.inner0(0).value() |
---|
| 112 | 7 |
---|
| 113 | >>> x.inner0(1).value() |
---|
| 114 | 1 |
---|
| 115 | |
---|
| 116 | >>> inner(n = 1, self = q).value() |
---|
| 117 | 1 |
---|
| 118 | |
---|
| 119 | >>> y = Y(value = 33) |
---|
| 120 | >>> y.raw(this = 1, that = 'the other')[1] |
---|
| 121 | {'this': 1, 'that': 'the other'} |
---|
| 122 | |
---|
| 123 | """ |
---|
| 124 | def run(args = None): |
---|
| 125 | import sys |
---|
| 126 | import doctest |
---|
| 127 | |
---|
| 128 | if args is not None: |
---|
| 129 | sys.argv = args |
---|
| 130 | return doctest.testmod(sys.modules.get(__name__)) |
---|
| 131 | |
---|
| 132 | if __name__ == '__main__': |
---|
| 133 | print "running..." |
---|
| 134 | import sys |
---|
| 135 | status = run()[0] |
---|
| 136 | if (status == 0): print "Done." |
---|
| 137 | sys.exit(status) |
---|
| 138 | |
---|
| 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 | |
---|