1
1
# -*- encoding:utf-8 -*-
2
2
from __future__ import division , absolute_import , print_function
3
3
4
+ import re
4
5
import sys
5
6
import textwrap
6
7
import warnings
@@ -316,19 +317,27 @@ def test_index():
316
317
assert_equal (len (doc ['index' ]['refguide' ]), 2 )
317
318
318
319
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 ):
320
329
a = textwrap .dedent (a )
321
330
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 ' )]
324
333
assert_list_equal (a , b )
325
334
326
335
327
336
def test_str ():
328
337
# doc_txt has the order of Notes and See Also sections flipped.
329
338
# This should be handled automatically, and so, one thing this test does
330
339
# 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 ),
332
341
"""numpy.multivariate_normal(mean, cov, shape=None, spam=None)
333
342
334
343
Draw values from a multivariate normal distribution with specified
@@ -387,6 +396,7 @@ def test_str():
387
396
388
397
See Also
389
398
--------
399
+
390
400
`some`_, `other`_, `funcs`_
391
401
392
402
`otherfunc`_
@@ -438,7 +448,7 @@ def test_str():
438
448
439
449
440
450
def test_yield_str ():
441
- non_blank_line_by_line_compare (str (doc_yields ),
451
+ line_by_line_compare (str (doc_yields ),
442
452
"""Test generator
443
453
444
454
Yields
@@ -455,7 +465,7 @@ def test_yield_str():
455
465
456
466
def test_sphinx_str ():
457
467
sphinx_doc = SphinxDocString (doc_txt )
458
- non_blank_line_by_line_compare (str (sphinx_doc ),
468
+ line_by_line_compare (str (sphinx_doc ),
459
469
"""
460
470
.. index:: random
461
471
single: random;distributions, random;gauss
@@ -572,7 +582,7 @@ def test_sphinx_str():
572
582
573
583
def test_sphinx_yields_str ():
574
584
sphinx_doc = SphinxDocString (doc_yields_txt )
575
- non_blank_line_by_line_compare (str (sphinx_doc ),
585
+ line_by_line_compare (str (sphinx_doc ),
576
586
"""Test generator
577
587
578
588
:Yields:
@@ -972,7 +982,7 @@ def test_duplicate_signature():
972
982
973
983
def test_class_members_doc ():
974
984
doc = ClassDoc (None , class_doc_txt )
975
- non_blank_line_by_line_compare (str (doc ),
985
+ line_by_line_compare (str (doc ),
976
986
"""
977
987
Foo
978
988
@@ -1008,9 +1018,7 @@ def test_class_members_doc():
1008
1018
Methods
1009
1019
-------
1010
1020
a
1011
-
1012
1021
b
1013
-
1014
1022
c
1015
1023
1016
1024
.. index::
@@ -1054,7 +1062,7 @@ def no_period(self):
1054
1062
return None
1055
1063
1056
1064
doc = SphinxClassDoc (Foo , class_doc_txt )
1057
- non_blank_line_by_line_compare (str (doc ),
1065
+ line_by_line_compare (str (doc ),
1058
1066
"""
1059
1067
Foo
1060
1068
@@ -1072,30 +1080,36 @@ def no_period(self):
1072
1080
1073
1081
:Attributes:
1074
1082
1075
- **t** : float
1083
+ t : float
1076
1084
Current time.
1077
- **y** : ndarray
1085
+
1086
+ y : ndarray
1078
1087
Current variable values.
1079
1088
1080
1089
* hello
1081
1090
* world
1091
+
1082
1092
:obj:`an_attribute <an_attribute>` : float
1083
1093
Test attribute
1084
- **no_docstring** : str
1094
+
1095
+ no_docstring : str
1085
1096
But a description
1086
- **no_docstring2** : str
1097
+
1098
+ no_docstring2 : str
1099
+
1087
1100
:obj:`multiline_sentence <multiline_sentence>`
1088
1101
This is a sentence.
1102
+
1089
1103
:obj:`midword_period <midword_period>`
1090
1104
The sentence for numpy.org.
1105
+
1091
1106
:obj:`no_period <no_period>`
1092
1107
This does not have a period
1093
1108
1094
1109
..
1095
1110
HACK to make autogen generate docs:
1096
1111
.. autosummary::
1097
1112
:toctree:
1098
-
1099
1113
an_attribute
1100
1114
multiline_sentence
1101
1115
midword_period
@@ -1114,14 +1128,13 @@ def no_period(self):
1114
1128
1115
1129
def test_templated_sections ():
1116
1130
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 ),
1119
1133
"""
1120
1134
.. rubric:: Examples
1121
1135
1122
1136
For usage examples, see `ode`.
1123
1137
1124
-
1125
1138
:Parameters:
1126
1139
1127
1140
f : callable ``f(t, y, *f_args)``
0 commit comments