122122 '''
123123doc = NumpyDocString (doc_txt )
124124
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+
125139
126140def test_signature ():
127141 assert doc ['Signature' ].startswith ('numpy.multivariate_normal(' )
@@ -165,8 +179,25 @@ def test_returns():
165179 assert desc [- 1 ].endswith ('anonymous return values.' )
166180
167181def 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 ():
168194 doc_text = """
169- Test generator
195+ Test having returns and yields.
196+
197+ Returns
198+ -------
199+ int
200+ The number of apples.
170201
171202Yields
172203------
@@ -176,15 +207,7 @@ def test_yields():
176207 The number of bananas.
177208
178209"""
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 )
188211
189212def test_notes ():
190213 assert doc ['Notes' ][0 ].startswith ('Instead' )
@@ -215,6 +238,9 @@ def non_blank_line_by_line_compare(a,b):
215238 "\n >>> %s\n <<< %s\n " %
216239 (n ,line ,b [n ]))
217240def 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.
218244 non_blank_line_by_line_compare (str (doc ),
219245"""numpy.multivariate_normal(mean, cov, shape=None, spam=None)
220246
@@ -324,6 +350,22 @@ def test_str():
324350 :refguide: random;distributions, random;gauss""" )
325351
326352
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+
327369def test_sphinx_str ():
328370 sphinx_doc = SphinxDocString (doc_txt )
329371 non_blank_line_by_line_compare (str (sphinx_doc ),
@@ -449,6 +491,27 @@ def test_sphinx_str():
449491""" )
450492
451493
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+
452515doc2 = NumpyDocString ("""
453516 Returns array of indices of the maximum values of along the given axis.
454517
0 commit comments