1# Copyright David Abrahams & Ralf W. Grosse-Kunsteve 2004-2006. 2# Distributed under the Boost 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 docstring_ext import * 6 7>>> def selected_doc(obj, *args): 8... doc = obj.__doc__.splitlines() 9... return "\\n".join(["|"+doc[i] for i in args]) 10 11>>> print(selected_doc(X.__init__, 1, 2, 3, 4, 5)) 12|__init__( (object)self, (int)value) -> None : 13| this is the __init__ function 14| its documentation has two lines. 15| 16| C++ signature : 17 18>>> print(selected_doc(X.value, 1, 2, 4, 7, 8, 10)) 19|value( (X)self) -> int : 20| gets the value of the object 21| C++ signature : 22|value( (X)self) -> int : 23| also gets the value of the object 24| C++ signature : 25 26>>> print(selected_doc(create, 1, 2, 3, 4)) 27|create( (int)value) -> X : 28| creates a new X object 29| 30| C++ signature : 31 32>>> print(selected_doc(fact, 1, 2, 3, 4)) 33|fact( (int)n) -> int : 34| compute the factorial 35| 36| C++ signature : 37 38>>> len(fact_usr_off_1.__doc__.splitlines()) 395 40>>> print(selected_doc(fact_usr_off_1, 1, 3)) 41|fact_usr_off_1( (int)n) -> int : 42| C++ signature : 43>>> len(fact_usr_on_1.__doc__.splitlines()) 446 45>>> print(selected_doc(fact_usr_on_1, 1, 2, 4)) 46|fact_usr_on_1( (int)n) -> int : 47| usr on 1 48| C++ signature : 49>>> len(fact_usr_off_2.__doc__.splitlines()) 505 51>>> print(selected_doc(fact_usr_off_2, 1, 3)) 52|fact_usr_off_2( (int)n) -> int : 53| C++ signature : 54>>> len(fact_usr_on_2.__doc__.splitlines()) 556 56>>> print(selected_doc(fact_usr_on_2, 1, 2, 4)) 57|fact_usr_on_2( (int)n) -> int : 58| usr on 2 59| C++ signature : 60 61 62>>> len(fact_sig_off_1.__doc__.splitlines()) 632 64>>> print(selected_doc(fact_sig_off_1, 1)) 65|sig off 1 66>>> len(fact_sig_on_1.__doc__.splitlines()) 676 68>>> print(selected_doc(fact_sig_on_1, 1, 2, 4)) 69|fact_sig_on_1( (int)n) -> int : 70| sig on 1 71| C++ signature : 72 73>>> len(fact_sig_off_2.__doc__.splitlines()) 742 75>>> print(selected_doc(fact_sig_off_2, 1)) 76|sig off 2 77>>> len(fact_sig_on_2.__doc__.splitlines()) 786 79>>> print(selected_doc(fact_sig_on_2, 1, 2, 4)) 80|fact_sig_on_2( (int)n) -> int : 81| sig on 2 82| C++ signature : 83 84 85>>> print(fact_usr_off_sig_off_1.__doc__) 86None 87>>> len(fact_usr_on_sig_on_1.__doc__.splitlines()) 886 89>>> print(selected_doc(fact_usr_on_sig_on_1, 1, 2, 4)) 90|fact_usr_on_sig_on_1( (int)n) -> int : 91| usr on sig on 1 92| C++ signature : 93 94>>> len(fact_usr_on_sig_off_1.__doc__.splitlines()) 952 96>>> print(selected_doc(fact_usr_on_sig_off_1, 1)) 97|usr on sig off 1 98>>> len(fact_usr_on_sig_on_2.__doc__.splitlines()) 996 100>>> print(selected_doc(fact_usr_on_sig_on_2, 1, 2, 4)) 101|fact_usr_on_sig_on_2( (int)n) -> int : 102| usr on sig on 2 103| C++ signature : 104 105>>> print(selected_doc(fact_usr_on_psig_on_csig_off_1, 1, 2)) 106|fact_usr_on_psig_on_csig_off_1( (int)n) -> int : 107| usr on psig on csig off 1 108 109>>> print(selected_doc(fact_usr_on_psig_off_csig_on_1, 1, 3)) 110|usr on psig off csig on 1 111|C++ signature : 112 113>>> print(fact_usr_off_psig_on_csig_off_1.__doc__.splitlines()[1]) 114fact_usr_off_psig_on_csig_off_1( (int)n) -> int 115 116>>> print(selected_doc(fact_usr_off_psig_off_csig_on_1,1)) 117|C++ signature : 118 119 120''' 121 122def run(args = None): 123 import sys 124 import doctest 125 126 if args is not None: 127 sys.argv = args 128 129 import docstring_ext 130 131 result = doctest.testmod(sys.modules.get(__name__)) 132 133 import pydoc 134 import re 135 docmodule = lambda m: re.sub(".\10", "", pydoc.text.docmodule(m)) 136 try: 137 print('printing module help:') 138 print(docmodule(docstring_ext)) 139 except object as x: 140 print('********* failed **********') 141 print(x) 142 result = list(result) 143 result[0] += 1 144 return tuple(result) 145 146 return result 147 148if __name__ == '__main__': 149 print("running...") 150 import sys 151 status = run()[0] 152 if (status == 0): print("Done.") 153 sys.exit(status) 154