122
122
'''
123
123
doc = NumpyDocString (doc_txt )
124
124
125
+ doc_yields_txt = """
126
+ Test generator
127
+
128
+ Yields
129
+ ------
130
+ a : int
131
+ The number of apples.
132
+ b : int
133
+ The number of bananas.
134
+ int
135
+ The number of unknowns.
136
+ """
137
+ doc_yields = NumpyDocString (doc_yields_txt )
138
+
125
139
126
140
def test_signature ():
127
141
assert doc ['Signature' ].startswith ('numpy.multivariate_normal(' )
@@ -165,8 +179,25 @@ def test_returns():
165
179
assert desc [- 1 ].endswith ('anonymous return values.' )
166
180
167
181
def test_yields ():
182
+ section = doc_yields ['Yields' ]
183
+ assert_equal (len (section ), 3 )
184
+ truth = [('a' , 'int' , 'apples.' ),
185
+ ('b' , 'int' , 'bananas.' ),
186
+ ('int' , '' , 'unknowns.' )]
187
+ for (arg , arg_type , desc ), (arg_ , arg_type_ , end ) in zip (section , truth ):
188
+ assert_equal (arg , arg_ )
189
+ assert_equal (arg_type , arg_type_ )
190
+ assert desc [0 ].startswith ('The number of' )
191
+ assert desc [0 ].endswith (end )
192
+
193
+ def test_returnyield ():
168
194
doc_text = """
169
- Test generator
195
+ Test having returns and yields.
196
+
197
+ Returns
198
+ -------
199
+ int
200
+ The number of apples.
170
201
171
202
Yields
172
203
------
@@ -176,15 +207,7 @@ def test_yields():
176
207
The number of bananas.
177
208
178
209
"""
179
- doc = NumpyDocString (doc_text )
180
- section = doc ['Yields' ]
181
- assert_equal (len (section ), 2 )
182
- truth = [('a' , 'apples.' ), ('b' , 'bananas.' )]
183
- for (arg , arg_type , desc ), (arg_true , ending ) in zip (section , truth ):
184
- assert_equal (arg , arg_true )
185
- assert_equal (arg_type , 'int' )
186
- assert desc [0 ].startswith ('The number of' )
187
- assert desc [0 ].endswith (ending )
210
+ assert_raises (ValueError , NumpyDocString , doc_text )
188
211
189
212
def test_notes ():
190
213
assert doc ['Notes' ][0 ].startswith ('Instead' )
@@ -215,6 +238,9 @@ def non_blank_line_by_line_compare(a,b):
215
238
"\n >>> %s\n <<< %s\n " %
216
239
(n ,line ,b [n ]))
217
240
def test_str ():
241
+ # doc_txt has the order of Notes and See Also sections flipped.
242
+ # This should be handled automatically, and so, one thing this test does
243
+ # is to make sure that See Also precedes Notes in the output.
218
244
non_blank_line_by_line_compare (str (doc ),
219
245
"""numpy.multivariate_normal(mean, cov, shape=None, spam=None)
220
246
@@ -324,6 +350,22 @@ def test_str():
324
350
:refguide: random;distributions, random;gauss""" )
325
351
326
352
353
+ def test_yield_str ():
354
+ non_blank_line_by_line_compare (str (doc_yields ),
355
+ """Test generator
356
+
357
+ Yields
358
+ ------
359
+ a : int
360
+ The number of apples.
361
+ b : int
362
+ The number of bananas.
363
+ int
364
+ The number of unknowns.
365
+
366
+ .. index:: """ )
367
+
368
+
327
369
def test_sphinx_str ():
328
370
sphinx_doc = SphinxDocString (doc_txt )
329
371
non_blank_line_by_line_compare (str (sphinx_doc ),
@@ -449,6 +491,27 @@ def test_sphinx_str():
449
491
""" )
450
492
451
493
494
+ def test_sphinx_yields_str ():
495
+ sphinx_doc = SphinxDocString (doc_yields_txt )
496
+ non_blank_line_by_line_compare (str (sphinx_doc ),
497
+ """Test generator
498
+
499
+ :Yields:
500
+
501
+ **a** : int
502
+
503
+ The number of apples.
504
+
505
+ **b** : int
506
+
507
+ The number of bananas.
508
+
509
+ int
510
+
511
+ The number of unknowns.
512
+ """ )
513
+
514
+
452
515
doc2 = NumpyDocString ("""
453
516
Returns array of indices of the maximum values of along the given axis.
454
517
0 commit comments