Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions numpydoc/numpydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ def is_docstring_section(node):
for sibling_section in sibling_sections:
if not sibling_section.children:
continue
last_child = sibling_section.children[-1]
if not isinstance(last_child, comment):
continue
if last_child.rawsource.strip() == DEDUPLICATION_TAG.strip():
return True

for child in sibling_section.children[::-1]:
if not isinstance(child, comment):
continue

if child.rawsource.strip() == DEDUPLICATION_TAG.strip():
return True

return False


Expand Down
21 changes: 21 additions & 0 deletions numpydoc/tests/test_full.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os.path as op
import re
import shutil

import pytest
Expand Down Expand Up @@ -65,3 +66,23 @@ def test_my_function(sphinx_app):
assert '*args' in html
# check xref (iterable should link using xref):
assert 'glossary.html#term-iterable' in html


def test_reference(sphinx_app):
"""Test for bad references e"""
out_dir = sphinx_app.outdir
html_files = [
["index.html"],
["generated", "numpydoc_test_module.my_function.html"],
["generated", "numpydoc_test_module.MyClass.html"],
]

for html_file in html_files:
html_file = op.join(out_dir, *html_file)

with open(html_file, 'r') as fid:
html = fid.read()

reference_list = re.findall(r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>', html)
for ref in reference_list:
assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1
1 change: 1 addition & 0 deletions numpydoc/tests/tinybuild/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ numpydoc_test_module
====================

.. automodule:: numpydoc_test_module
:members:
22 changes: 20 additions & 2 deletions numpydoc/tests/tinybuild/numpydoc_test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

MyClass
my_function

Reference [1]_

References
----------
.. [1] https://numpydoc.readthedocs.io

"""

__all__ = ['MyClass', 'my_function']
Expand All @@ -15,22 +22,33 @@
class MyClass(object):
"""A class.

Reference [2]_

Parameters
----------
*args : iterable
Arguments.
**kwargs : dict
Keyword arguments.

References
----------
.. [2] https://numpydoc.readthedocs.io
"""

def __init__(self, *args, **kwargs):
pass

def example(self):
"""Exampel function
"""
pass


def my_function(*args, **kwargs):
"""Return None.

See [1]_.
See [3]_.

Parameters
----------
Expand All @@ -46,6 +64,6 @@ def my_function(*args, **kwargs):

References
----------
.. [1] https://numpydoc.readthedocs.io
.. [3] https://numpydoc.readthedocs.io
"""
return None