From 5554b47e2157b1092bb04cb7dccfa8da7fdcb8a1 Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Mon, 13 Apr 2020 13:18:31 +0200 Subject: [PATCH 1/4] Fixes references outside function (#214) --- numpydoc/numpydoc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index c68a54a0..79ad9e66 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -88,6 +88,8 @@ def is_docstring_section(node): for sibling_section in sibling_sections: if not sibling_section.children: continue + if isinstance(sibling_section, section): + return True last_child = sibling_section.children[-1] if not isinstance(last_child, comment): continue From 959c41dae3e035baf0312c4077caae9fc21bc870 Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Tue, 14 Apr 2020 20:01:36 +0200 Subject: [PATCH 2/4] Fixes reference in class with a method in it (#259) --- numpydoc/numpydoc.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index 79ad9e66..b7d10de9 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -88,13 +88,14 @@ def is_docstring_section(node): for sibling_section in sibling_sections: if not sibling_section.children: continue - if isinstance(sibling_section, section): - return True - 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 From bcae505f7b90cb0fe47482f585581cd70329cab0 Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Sun, 19 Apr 2020 12:07:20 +0200 Subject: [PATCH 3/4] Added unittest to reference --- numpydoc/tests/test_full.py | 21 ++++++++++++++++++ numpydoc/tests/tinybuild/index.rst | 1 + .../tests/tinybuild/numpydoc_test_module.py | 22 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index 9fc8fb6b..dfcf68b2 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -1,4 +1,5 @@ import os.path as op +import re import shutil import pytest @@ -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>', html) + for ref in reference_list: + assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1 diff --git a/numpydoc/tests/tinybuild/index.rst b/numpydoc/tests/tinybuild/index.rst index a078ff88..9d5c1d9c 100644 --- a/numpydoc/tests/tinybuild/index.rst +++ b/numpydoc/tests/tinybuild/index.rst @@ -2,3 +2,4 @@ numpydoc_test_module ==================== .. automodule:: numpydoc_test_module + :members: diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 85d990ca..3c23dc4c 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -7,6 +7,13 @@ MyClass my_function + +Reference [1]_ + +References +---------- +.. [1] https://numpydoc.readthedocs.io + """ __all__ = ['MyClass', 'my_function'] @@ -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 ---------- @@ -46,6 +64,6 @@ def my_function(*args, **kwargs): References ---------- - .. [1] https://numpydoc.readthedocs.io + .. [3] https://numpydoc.readthedocs.io """ return None From 9b24ccc44074fbc52a6ec33180f8f3197380d2da Mon Sep 17 00:00:00 2001 From: Simon Hoxbro Date: Sun, 19 Apr 2020 15:28:09 +0200 Subject: [PATCH 4/4] Check if reference list in test_full is correct size --- numpydoc/tests/test_full.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index dfcf68b2..73837759 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -69,7 +69,7 @@ def test_my_function(sphinx_app): def test_reference(sphinx_app): - """Test for bad references e""" + """Test for bad references""" out_dir = sphinx_app.outdir html_files = [ ["index.html"], @@ -77,12 +77,16 @@ def test_reference(sphinx_app): ["generated", "numpydoc_test_module.MyClass.html"], ] - for html_file in html_files: + expected_lengths = [3, 1, 1] + + for html_file, expected_length in zip(html_files, expected_lengths): html_file = op.join(out_dir, *html_file) with open(html_file, 'r') as fid: html = fid.read() reference_list = re.findall(r'(.*)<\/a>', html) + + assert len(reference_list) == expected_length for ref in reference_list: assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1