1- # Copyright David Abrahams 2004. Distributed under the Boost
2- # Software License, Version 1.0. (See accompanying
1+ # Copyright David Abrahams & Ralf W. Grosse-Kunsteve 2004-2006.
2+ # Distributed under the Boost Software License, Version 1.0. (See accompanying
33# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
44'''
55>>> from docstring_ext import *
66
77>>> def selected_doc(obj, *args):
88... doc = obj.__doc__.splitlines()
9- ... return [ doc[i] for i in args]
9+ ... return " \\ n".join(["|"+ doc[i] for i in args])
1010
11- >>> selected_doc(X.__init__, 0, 1, 2)
12- ['this is the __init__ function', 'its documentation has two lines.', 'C++ signature:']
11+ >>> print selected_doc(X.__init__, 0, 1, 2)
12+ |this is the __init__ function
13+ |its documentation has two lines.
14+ |C++ signature:
1315
14- >>> selected_doc(X.value, 0, 1, 3, 4, 5)
15- ['gets the value of the object', 'C++ signature:', '', 'also gets the value of the object', 'C++ signature:']
16+ >>> print selected_doc(X.value, 0, 1, 3, 4, 5)
17+ |gets the value of the object
18+ |C++ signature:
19+ |
20+ |also gets the value of the object
21+ |C++ signature:
1622
17- >>> selected_doc(create, 0, 1)
18- ['creates a new X object', 'C++ signature:']
23+ >>> print selected_doc(create, 0, 1)
24+ |creates a new X object
25+ |C++ signature:
1926
20- >>> selected_doc(fact, 0, 1)
21- ['compute the factorial', 'C++ signature:']
27+ >>> print selected_doc(fact, 0, 1)
28+ |compute the factorial
29+ |C++ signature:
2230
2331>>> len(fact_usr_off_1.__doc__.splitlines())
24322
25- >>> selected_doc(fact_usr_off_1, 0)
26- [' C++ signature:']
33+ >>> print selected_doc(fact_usr_off_1, 0)
34+ | C++ signature:
2735>>> len(fact_usr_on_1.__doc__.splitlines())
28363
29- >>> selected_doc(fact_usr_on_1, 0, 1)
30- ['usr on 1', 'C++ signature:']
37+ >>> print selected_doc(fact_usr_on_1, 0, 1)
38+ |usr on 1
39+ |C++ signature:
3140>>> len(fact_usr_off_2.__doc__.splitlines())
32412
33- >>> selected_doc(fact_usr_off_2, 0)
34- [' C++ signature:']
42+ >>> print selected_doc(fact_usr_off_2, 0)
43+ | C++ signature:
3544>>> len(fact_usr_on_2.__doc__.splitlines())
36453
37- >>> selected_doc(fact_usr_on_2, 0, 1)
38- ['usr on 2', 'C++ signature:']
46+ >>> print selected_doc(fact_usr_on_2, 0, 1)
47+ |usr on 2
48+ |C++ signature:
3949
4050>>> len(fact_sig_off_1.__doc__.splitlines())
41511
42- >>> selected_doc(fact_sig_off_1, 0)
43- [' sig off 1']
52+ >>> print selected_doc(fact_sig_off_1, 0)
53+ | sig off 1
4454>>> len(fact_sig_on_1.__doc__.splitlines())
45553
46- >>> selected_doc(fact_sig_on_1, 0, 1)
47- ['sig on 1', 'C++ signature:']
56+ >>> print selected_doc(fact_sig_on_1, 0, 1)
57+ |sig on 1
58+ |C++ signature:
4859>>> len(fact_sig_off_2.__doc__.splitlines())
49601
50- >>> selected_doc(fact_sig_off_2, 0)
51- [' sig off 2']
61+ >>> print selected_doc(fact_sig_off_2, 0)
62+ | sig off 2
5263>>> len(fact_sig_on_2.__doc__.splitlines())
53643
54- >>> selected_doc(fact_sig_on_2, 0, 1)
55- ['sig on 2', 'C++ signature:']
65+ >>> print selected_doc(fact_sig_on_2, 0, 1)
66+ |sig on 2
67+ |C++ signature:
5668
5769>>> print fact_usr_off_sig_off_1.__doc__
5870None
5971>>> len(fact_usr_on_sig_on_1.__doc__.splitlines())
60723
61- >>> selected_doc(fact_usr_on_sig_on_1, 0, 1)
62- ['usr on sig on 1', 'C++ signature:']
73+ >>> print selected_doc(fact_usr_on_sig_on_1, 0, 1)
74+ |usr on sig on 1
75+ |C++ signature:
6376>>> len(fact_usr_on_sig_off_1.__doc__.splitlines())
64771
65- >>> selected_doc(fact_usr_on_sig_off_1, 0)
66- [' usr on sig off 1']
78+ >>> print selected_doc(fact_usr_on_sig_off_1, 0)
79+ | usr on sig off 1
6780>>> len(fact_usr_on_sig_on_2.__doc__.splitlines())
68813
69- >>> selected_doc(fact_usr_on_sig_on_2, 0, 1)
70- ['usr on sig on 2', 'C++ signature:']
82+ >>> print selected_doc(fact_usr_on_sig_on_2, 0, 1)
83+ |usr on sig on 2
84+ |C++ signature:
7185>>> print fact_usr_off_sig_off_2.__doc__
7286None
7387
@@ -79,11 +93,11 @@ def run(args = None):
7993
8094 if args is not None :
8195 sys .argv = args
82-
96+
8397 import docstring_ext
84-
98+
8599 result = doctest .testmod (sys .modules .get (__name__ ))
86-
100+
87101 import pydoc
88102 import re
89103 docmodule = lambda m : re .sub (".\10 " , "" , pydoc .text .docmodule (m ))
@@ -96,9 +110,9 @@ def run(args = None):
96110 result = list (result )
97111 result [0 ] += 1
98112 return tuple (result )
99-
113+
100114 return result
101-
115+
102116if __name__ == '__main__' :
103117 print "running..."
104118 import sys
0 commit comments