Skip to content

Commit d7f30e7

Browse files
committed
Stricter comparison of whitespace in testing
1 parent 698b456 commit d7f30e7

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

numpydoc/docscrape.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ def _str_param_list(self, name):
403403
out += ['%s : %s' % (param, param_type)]
404404
else:
405405
out += [param]
406-
out += self._str_indent(desc)
406+
if desc and ''.join(desc).strip():
407+
out += self._str_indent(desc)
407408
out += ['']
408409
return out
409410

numpydoc/docscrape_sphinx.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,6 @@ def _str_section(self, name):
285285
out = []
286286
if self[name]:
287287
out += self._str_header(name)
288-
out += ['']
289288
content = textwrap.dedent("\n".join(self[name])).split("\n")
290289
out += content
291290
out += ['']
@@ -304,6 +303,7 @@ def _str_warnings(self):
304303
if self['Warnings']:
305304
out = ['.. warning::', '']
306305
out += self._str_indent(self['Warnings'])
306+
out += ['']
307307
return out
308308

309309
def _str_index(self):
@@ -320,6 +320,7 @@ def _str_index(self):
320320
out += [' single: %s' % (', '.join(references))]
321321
else:
322322
out += [' %s: %s' % (section, ','.join(references))]
323+
out += ['']
323324
return out
324325

325326
def _str_references(self):

numpydoc/tests/test_docscrape.py

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- encoding:utf-8 -*-
22
from __future__ import division, absolute_import, print_function
33

4+
import re
45
import sys
56
import textwrap
67
import 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

327336
def 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
334343
Draw values from a multivariate normal distribution with specified
@@ -387,6 +396,7 @@ def test_str():
387396
388397
See Also
389398
--------
399+
390400
`some`_, `other`_, `funcs`_
391401
392402
`otherfunc`_
@@ -438,7 +448,7 @@ def test_str():
438448

439449

440450
def 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
444454
Yields
@@ -455,7 +465,7 @@ def test_yield_str():
455465

456466
def 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

573583
def 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

973983
def 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

11151129
def 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

Comments
 (0)