Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/docstring.py @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.8 KB
Line 
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__, 0, 1, 2)
12|this is the __init__ function
13|its documentation has two lines.
14|C++ signature:
15
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:
22
23>>> print selected_doc(create, 0, 1)
24|creates a new X object
25|C++ signature:
26
27>>> print selected_doc(fact, 0, 1)
28|compute the factorial
29|C++ signature:
30
31>>> len(fact_usr_off_1.__doc__.splitlines())
322
33>>> print selected_doc(fact_usr_off_1, 0)
34|C++ signature:
35>>> len(fact_usr_on_1.__doc__.splitlines())
363
37>>> print selected_doc(fact_usr_on_1, 0, 1)
38|usr on 1
39|C++ signature:
40>>> len(fact_usr_off_2.__doc__.splitlines())
412
42>>> print selected_doc(fact_usr_off_2, 0)
43|C++ signature:
44>>> len(fact_usr_on_2.__doc__.splitlines())
453
46>>> print selected_doc(fact_usr_on_2, 0, 1)
47|usr on 2
48|C++ signature:
49
50>>> len(fact_sig_off_1.__doc__.splitlines())
511
52>>> print selected_doc(fact_sig_off_1, 0)
53|sig off 1
54>>> len(fact_sig_on_1.__doc__.splitlines())
553
56>>> print selected_doc(fact_sig_on_1, 0, 1)
57|sig on 1
58|C++ signature:
59>>> len(fact_sig_off_2.__doc__.splitlines())
601
61>>> print selected_doc(fact_sig_off_2, 0)
62|sig off 2
63>>> len(fact_sig_on_2.__doc__.splitlines())
643
65>>> print selected_doc(fact_sig_on_2, 0, 1)
66|sig on 2
67|C++ signature:
68
69>>> print fact_usr_off_sig_off_1.__doc__
70None
71>>> len(fact_usr_on_sig_on_1.__doc__.splitlines())
723
73>>> print selected_doc(fact_usr_on_sig_on_1, 0, 1)
74|usr on sig on 1
75|C++ signature:
76>>> len(fact_usr_on_sig_off_1.__doc__.splitlines())
771
78>>> print selected_doc(fact_usr_on_sig_off_1, 0)
79|usr on sig off 1
80>>> len(fact_usr_on_sig_on_2.__doc__.splitlines())
813
82>>> print selected_doc(fact_usr_on_sig_on_2, 0, 1)
83|usr on sig on 2
84|C++ signature:
85>>> print fact_usr_off_sig_off_2.__doc__
86None
87
88'''
89
90def run(args = None):
91    import sys
92    import doctest
93
94    if args is not None:
95        sys.argv = args
96
97    import docstring_ext
98
99    result = doctest.testmod(sys.modules.get(__name__))
100
101    import pydoc
102    import re
103    docmodule = lambda m: re.sub(".\10", "", pydoc.text.docmodule(m))
104    try:
105        print 'printing module help:'
106        print docmodule(docstring_ext)
107    except object, x:
108        print '********* failed **********'
109        print x
110        result = list(result)
111        result[0] += 1
112        return tuple(result)
113
114    return result
115
116if __name__ == '__main__':
117    print "running..."
118    import sys
119    status = run()[0]
120    if (status == 0): print "Done."
121    sys.exit(status)
Note: See TracBrowser for help on using the repository browser.