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 defaults_ext import * 6>>> bar(1) 7'int(1); char(D); string(default); double(0.0); ' 8 9>>> bar(2, 'X') 10'int(2); char(X); string(default); double(0.0); ' 11 12>>> bar(3, 'Y', "Hello World") 13'int(3); char(Y); string(Hello World); double(0.0); ' 14 15>>> bar(4, 'Z', "Hi There", 3.3) 16'int(4); char(Z); string(Hi There); double(3.3); ' 17 18>>> foo(1) 19'int(1); char(D); string(default); double(0.0); ' 20 21>>> foo(2, 'X') 22'int(2); char(X); string(default); double(0.0); ' 23 24>>> foo(3, 'Y', "Hello World") 25'int(3); char(Y); string(Hello World); double(0.0); ' 26 27>>> foo(4, 'Z', "Hi There", 3.3) 28'int(4); char(Z); string(Hi There); double(3.3); ' 29 30>>> x = X() 31>>> x.bar(1) 32'int(1); char(D); string(default); double(0.0); ' 33 34>>> x.bar(2, 'X') 35'int(2); char(X); string(default); double(0.0); ' 36 37>>> x.bar(3, 'Y', "Hello World") 38'int(3); char(Y); string(Hello World); double(0.0); ' 39 40>>> x.bar(4, 'Z', "Hi There", 3.3) 41'int(4); char(Z); string(Hi There); double(3.3); ' 42 43>>> x.foo(5) 44'int(5); bool(0); ' 45 46>>> x.foo(6, 0) 47'int(6); bool(0); ' 48 49>>> x.foo(7, 1) 50'int(7); bool(1); ' 51 52>>> x.foo("A") 53'string(A); bool(0); ' 54 55>>> x.foo("B", False) 56'string(B); bool(0); ' 57 58>>> x.foo("C", True) 59'string(C); bool(1); ' 60 61>>> x.foo([0,1,2], [2,3,4]) 62'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' 63 64>>> x.foo([0,1,2], [2,3,4], False) 65'list([0, 1, 2]); list([2, 3, 4]); bool(0); ' 66 67>>> x.foo([0,1,2], [2,3,4], True) 68'list([0, 1, 2]); list([2, 3, 4]); bool(1); ' 69 70>>> x = X(1) 71>>> x.get_state() 72'int(1); char(D); string(constructor); double(0.0); ' 73 74>>> x = X(1, 'X') 75>>> x.get_state() 76'int(1); char(X); string(constructor); double(0.0); ' 77 78>>> x = X(1, 'X', "Yabadabadoo") 79>>> x.get_state() 80'int(1); char(X); string(Yabadabadoo); double(0.0); ' 81 82>>> x = X(1, 'X', "Phoenix", 3.65) 83>>> x.get_state() 84'int(1); char(X); string(Phoenix); double(3.65); ' 85 86>>> x.bar2().get_state() 87'int(0); char(D); string(default); double(0.0); ' 88 89>>> x.bar2(1).get_state() 90'int(1); char(D); string(default); double(0.0); ' 91 92>>> x.bar2(1, 'K').get_state() 93'int(1); char(K); string(default); double(0.0); ' 94 95>>> x.bar2(1, 'K', "Kim").get_state() 96'int(1); char(K); string(Kim); double(0.0); ' 97 98>>> x.bar2(1, 'K', "Kim", 9.9).get_state() 99'int(1); char(K); string(Kim); double(9.9); ' 100 101>>> x = X("Phoenix", 1) 102>>> x.get_state() 103'Got exactly two arguments from constructor: string(Phoenix); bool(1); ' 104 105>>> def selected_doc(obj, *args): 106... doc = obj.__doc__.splitlines() 107... return "\\n".join(["|"+doc[i] for i in args]) 108 109>>> print(selected_doc(X.__init__, 1, 2, 4, 7, 9)) 110|__init__( (object)self [, (int)a [, (str)b [, (str)c [, (float)d]]]]) -> None : 111| doc of init 112| C++ signature : 113|__init__( (object)self, (str)s, (bool)b) -> None : 114| C++ signature : 115 116>>> print(selected_doc(Y.__init__, 1, 2, 4)) 117|__init__( (object)arg1) -> None : 118| doc of Y init 119| C++ signature : 120 121>>> print(selected_doc(X.bar2, 1, 2, 4)) 122|bar2( (X)arg1 [, (int)arg2 [, (str)arg3 [, (str)arg4 [, (float)arg5]]]]) -> Y : 123| doc of X::bar2 124| C++ signature : 125 126""" 127def run(args = None): 128 import sys 129 import doctest 130 131 if args is not None: 132 sys.argv = args 133 return doctest.testmod(sys.modules.get(__name__)) 134 135if __name__ == '__main__': 136 print("running...") 137 import sys 138 status = run()[0] 139 if (status == 0): print("Done.") 140 sys.exit(status) 141