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