File tree Expand file tree Collapse file tree 4 files changed +54
-7
lines changed Expand file tree Collapse file tree 4 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -88,11 +88,14 @@ def is_docstring_section(node):
8888 for sibling_section in sibling_sections :
8989 if not sibling_section .children :
9090 continue
91- last_child = sibling_section .children [- 1 ]
92- if not isinstance (last_child , comment ):
93- continue
94- if last_child .rawsource .strip () == DEDUPLICATION_TAG .strip ():
95- return True
91+
92+ for child in sibling_section .children [::- 1 ]:
93+ if not isinstance (child , comment ):
94+ continue
95+
96+ if child .rawsource .strip () == DEDUPLICATION_TAG .strip ():
97+ return True
98+
9699 return False
97100
98101
Original file line number Diff line number Diff line change 11import os .path as op
2+ import re
23import shutil
34
45import pytest
@@ -65,3 +66,27 @@ def test_my_function(sphinx_app):
6566 assert '*args' in html
6667 # check xref (iterable should link using xref):
6768 assert 'glossary.html#term-iterable' in html
69+
70+
71+ def test_reference (sphinx_app ):
72+ """Test for bad references"""
73+ out_dir = sphinx_app .outdir
74+ html_files = [
75+ ["index.html" ],
76+ ["generated" , "numpydoc_test_module.my_function.html" ],
77+ ["generated" , "numpydoc_test_module.MyClass.html" ],
78+ ]
79+
80+ expected_lengths = [3 , 1 , 1 ]
81+
82+ for html_file , expected_length in zip (html_files , expected_lengths ):
83+ html_file = op .join (out_dir , * html_file )
84+
85+ with open (html_file , 'r' ) as fid :
86+ html = fid .read ()
87+
88+ reference_list = re .findall (r'<a class="fn-backref" href="\#id\d+">(.*)<\/a>' , html )
89+
90+ assert len (reference_list ) == expected_length
91+ for ref in reference_list :
92+ assert '-' not in ref # Bad reference if it contains "-" e.g. R1896e33633d5-1
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ numpydoc_test_module
22====================
33
44.. automodule :: numpydoc_test_module
5+ :members:
Original file line number Diff line number Diff line change 77
88 MyClass
99 my_function
10+
11+ Reference [1]_
12+
13+ References
14+ ----------
15+ .. [1] https://numpydoc.readthedocs.io
16+
1017"""
1118
1219__all__ = ['MyClass' , 'my_function' ]
1522class MyClass (object ):
1623 """A class.
1724
25+ Reference [2]_
26+
1827 Parameters
1928 ----------
2029 *args : iterable
2130 Arguments.
2231 **kwargs : dict
2332 Keyword arguments.
33+
34+ References
35+ ----------
36+ .. [2] https://numpydoc.readthedocs.io
2437 """
2538
2639 def __init__ (self , * args , ** kwargs ):
2740 pass
2841
42+ def example (self ):
43+ """Exampel function
44+ """
45+ pass
46+
2947
3048def my_function (* args , ** kwargs ):
3149 """Return None.
3250
33- See [1 ]_.
51+ See [3 ]_.
3452
3553 Parameters
3654 ----------
@@ -46,6 +64,6 @@ def my_function(*args, **kwargs):
4664
4765 References
4866 ----------
49- .. [1 ] https://numpydoc.readthedocs.io
67+ .. [3 ] https://numpydoc.readthedocs.io
5068 """
5169 return None
You can’t perform that action at this time.
0 commit comments