| 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()) |
|---|
| 32 | 2 |
|---|
| 33 | >>> print selected_doc(fact_usr_off_1, 0) |
|---|
| 34 | |C++ signature: |
|---|
| 35 | >>> len(fact_usr_on_1.__doc__.splitlines()) |
|---|
| 36 | 3 |
|---|
| 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()) |
|---|
| 41 | 2 |
|---|
| 42 | >>> print selected_doc(fact_usr_off_2, 0) |
|---|
| 43 | |C++ signature: |
|---|
| 44 | >>> len(fact_usr_on_2.__doc__.splitlines()) |
|---|
| 45 | 3 |
|---|
| 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()) |
|---|
| 51 | 1 |
|---|
| 52 | >>> print selected_doc(fact_sig_off_1, 0) |
|---|
| 53 | |sig off 1 |
|---|
| 54 | >>> len(fact_sig_on_1.__doc__.splitlines()) |
|---|
| 55 | 3 |
|---|
| 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()) |
|---|
| 60 | 1 |
|---|
| 61 | >>> print selected_doc(fact_sig_off_2, 0) |
|---|
| 62 | |sig off 2 |
|---|
| 63 | >>> len(fact_sig_on_2.__doc__.splitlines()) |
|---|
| 64 | 3 |
|---|
| 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__ |
|---|
| 70 | None |
|---|
| 71 | >>> len(fact_usr_on_sig_on_1.__doc__.splitlines()) |
|---|
| 72 | 3 |
|---|
| 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()) |
|---|
| 77 | 1 |
|---|
| 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()) |
|---|
| 81 | 3 |
|---|
| 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__ |
|---|
| 86 | None |
|---|
| 87 | |
|---|
| 88 | ''' |
|---|
| 89 | |
|---|
| 90 | def 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 | |
|---|
| 116 | if __name__ == '__main__': |
|---|
| 117 | print "running..." |
|---|
| 118 | import sys |
|---|
| 119 | status = run()[0] |
|---|
| 120 | if (status == 0): print "Done." |
|---|
| 121 | sys.exit(status) |
|---|