Skip to content

Commit 8897cc9

Browse files
author
Ralf W. Grosse-Kunstleve
committed
selected_doc() helper function modified to increase readability
[SVN r32339]
1 parent 335cd02 commit 8897cc9

File tree

2 files changed

+76
-48
lines changed

2 files changed

+76
-48
lines changed

test/defaults.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,30 @@
111111
112112
>>> def selected_doc(obj, *args):
113113
... doc = obj.__doc__.splitlines()
114-
... return [doc[i] for i in args]
115-
116-
>>> selected_doc(X.__init__, 0, 2, 4, 6, 8, 9, 10, 12)
117-
['C++ signature:', 'C++ signature:', 'C++ signature:', 'C++ signature:', '', 'doc of init', 'C++ signature:', 'C++ signature:']
118-
119-
>>> selected_doc(Y.__init__, 0, 1)
120-
['doc of Y init', 'C++ signature:']
121-
122-
>>> selected_doc(X.bar2, 0, 2, 4, 6, 8, 9, 10)
123-
['C++ signature:', 'C++ signature:', 'C++ signature:', 'C++ signature:', '', 'doc of X::bar2', 'C++ signature:']
114+
... return "\\n".join(["|"+doc[i] for i in args])
115+
116+
>>> print selected_doc(X.__init__, 0, 2, 4, 6, 8, 9, 10, 12)
117+
|C++ signature:
118+
|C++ signature:
119+
|C++ signature:
120+
|C++ signature:
121+
|
122+
|doc of init
123+
|C++ signature:
124+
|C++ signature:
125+
126+
>>> print selected_doc(Y.__init__, 0, 1)
127+
|doc of Y init
128+
|C++ signature:
129+
130+
>>> print selected_doc(X.bar2, 0, 2, 4, 6, 8, 9, 10)
131+
|C++ signature:
132+
|C++ signature:
133+
|C++ signature:
134+
|C++ signature:
135+
|
136+
|doc of X::bar2
137+
|C++ signature:
124138
125139
"""
126140
def run(args = None):

test/docstring.py

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,87 @@
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())
2432
2
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())
2836
3
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())
3241
2
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())
3645
3
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())
4151
1
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())
4555
3
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())
4960
1
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())
5364
3
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__
5870
None
5971
>>> len(fact_usr_on_sig_on_1.__doc__.splitlines())
6072
3
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())
6477
1
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())
6881
3
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__
7286
None
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+
102116
if __name__ == '__main__':
103117
print "running..."
104118
import sys

0 commit comments

Comments
 (0)