11# -*- encoding:utf-8 -*-
22from __future__ import division , absolute_import , print_function
33
4+ import re
45import sys
56import textwrap
67import warnings
@@ -316,19 +317,27 @@ def test_index():
316317 assert_equal (len (doc ['index' ]['refguide' ]), 2 )
317318
318319
319- def non_blank_line_by_line_compare (a , b ):
320+ def _strip_blank_lines (s ):
321+ "Remove leading, trailing and multiple blank lines"
322+ s = re .sub (r'^\s*\n' , '' , s )
323+ s = re .sub (r'\n\s*$' , '' , s )
324+ s = re .sub (r'\n\s*\n' , r'\n\n' , s )
325+ return s
326+
327+
328+ def line_by_line_compare (a , b ):
320329 a = textwrap .dedent (a )
321330 b = textwrap .dedent (b )
322- a = [l .rstrip () for l in a .split ('\n ' ) if l . strip ( )]
323- b = [l .rstrip () for l in b .split ('\n ' ) if l . strip ( )]
331+ a = [l .rstrip () for l in _strip_blank_lines ( a ) .split ('\n ' )]
332+ b = [l .rstrip () for l in _strip_blank_lines ( b ) .split ('\n ' )]
324333 assert_list_equal (a , b )
325334
326335
327336def test_str ():
328337 # doc_txt has the order of Notes and See Also sections flipped.
329338 # This should be handled automatically, and so, one thing this test does
330339 # is to make sure that See Also precedes Notes in the output.
331- non_blank_line_by_line_compare (str (doc ),
340+ line_by_line_compare (str (doc ),
332341"""numpy.multivariate_normal(mean, cov, shape=None, spam=None)
333342
334343Draw values from a multivariate normal distribution with specified
@@ -387,6 +396,7 @@ def test_str():
387396
388397See Also
389398--------
399+
390400`some`_, `other`_, `funcs`_
391401
392402`otherfunc`_
@@ -438,7 +448,7 @@ def test_str():
438448
439449
440450def test_yield_str ():
441- non_blank_line_by_line_compare (str (doc_yields ),
451+ line_by_line_compare (str (doc_yields ),
442452"""Test generator
443453
444454Yields
@@ -455,7 +465,7 @@ def test_yield_str():
455465
456466def test_sphinx_str ():
457467 sphinx_doc = SphinxDocString (doc_txt )
458- non_blank_line_by_line_compare (str (sphinx_doc ),
468+ line_by_line_compare (str (sphinx_doc ),
459469"""
460470.. index:: random
461471 single: random;distributions, random;gauss
@@ -572,7 +582,7 @@ def test_sphinx_str():
572582
573583def test_sphinx_yields_str ():
574584 sphinx_doc = SphinxDocString (doc_yields_txt )
575- non_blank_line_by_line_compare (str (sphinx_doc ),
585+ line_by_line_compare (str (sphinx_doc ),
576586"""Test generator
577587
578588:Yields:
@@ -972,7 +982,7 @@ def test_duplicate_signature():
972982
973983def test_class_members_doc ():
974984 doc = ClassDoc (None , class_doc_txt )
975- non_blank_line_by_line_compare (str (doc ),
985+ line_by_line_compare (str (doc ),
976986 """
977987 Foo
978988
@@ -1008,9 +1018,7 @@ def test_class_members_doc():
10081018 Methods
10091019 -------
10101020 a
1011-
10121021 b
1013-
10141022 c
10151023
10161024 .. index::
@@ -1054,7 +1062,7 @@ def no_period(self):
10541062 return None
10551063
10561064 doc = SphinxClassDoc (Foo , class_doc_txt )
1057- non_blank_line_by_line_compare (str (doc ),
1065+ line_by_line_compare (str (doc ),
10581066 """
10591067 Foo
10601068
@@ -1072,30 +1080,36 @@ def no_period(self):
10721080
10731081 :Attributes:
10741082
1075- **t** : float
1083+ t : float
10761084 Current time.
1077- **y** : ndarray
1085+
1086+ y : ndarray
10781087 Current variable values.
10791088
10801089 * hello
10811090 * world
1091+
10821092 :obj:`an_attribute <an_attribute>` : float
10831093 Test attribute
1084- **no_docstring** : str
1094+
1095+ no_docstring : str
10851096 But a description
1086- **no_docstring2** : str
1097+
1098+ no_docstring2 : str
1099+
10871100 :obj:`multiline_sentence <multiline_sentence>`
10881101 This is a sentence.
1102+
10891103 :obj:`midword_period <midword_period>`
10901104 The sentence for numpy.org.
1105+
10911106 :obj:`no_period <no_period>`
10921107 This does not have a period
10931108
10941109 ..
10951110 HACK to make autogen generate docs:
10961111 .. autosummary::
10971112 :toctree:
1098-
10991113 an_attribute
11001114 multiline_sentence
11011115 midword_period
@@ -1114,14 +1128,13 @@ def no_period(self):
11141128
11151129def test_templated_sections ():
11161130 doc = SphinxClassDoc (None , class_doc_txt ,
1117- config = {'template' : jinja2 .Template ('{{examples}}{{parameters}}' )})
1118- non_blank_line_by_line_compare (str (doc ),
1131+ config = {'template' : jinja2 .Template ('{{examples}}\n {{parameters}}' )})
1132+ line_by_line_compare (str (doc ),
11191133 """
11201134 .. rubric:: Examples
11211135
11221136 For usage examples, see `ode`.
11231137
1124-
11251138 :Parameters:
11261139
11271140 f : callable ``f(t, y, *f_args)``
0 commit comments