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):
88
88
for sibling_section in sibling_sections :
89
89
if not sibling_section .children :
90
90
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
+
96
99
return False
97
100
98
101
Original file line number Diff line number Diff line change 1
1
import os .path as op
2
+ import re
2
3
import shutil
3
4
4
5
import pytest
@@ -65,3 +66,27 @@ def test_my_function(sphinx_app):
65
66
assert '*args' in html
66
67
# check xref (iterable should link using xref):
67
68
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
2
2
====================
3
3
4
4
.. automodule :: numpydoc_test_module
5
+ :members:
Original file line number Diff line number Diff line change 7
7
8
8
MyClass
9
9
my_function
10
+
11
+ Reference [1]_
12
+
13
+ References
14
+ ----------
15
+ .. [1] https://numpydoc.readthedocs.io
16
+
10
17
"""
11
18
12
19
__all__ = ['MyClass' , 'my_function' ]
15
22
class MyClass (object ):
16
23
"""A class.
17
24
25
+ Reference [2]_
26
+
18
27
Parameters
19
28
----------
20
29
*args : iterable
21
30
Arguments.
22
31
**kwargs : dict
23
32
Keyword arguments.
33
+
34
+ References
35
+ ----------
36
+ .. [2] https://numpydoc.readthedocs.io
24
37
"""
25
38
26
39
def __init__ (self , * args , ** kwargs ):
27
40
pass
28
41
42
+ def example (self ):
43
+ """Exampel function
44
+ """
45
+ pass
46
+
29
47
30
48
def my_function (* args , ** kwargs ):
31
49
"""Return None.
32
50
33
- See [1 ]_.
51
+ See [3 ]_.
34
52
35
53
Parameters
36
54
----------
@@ -46,6 +64,6 @@ def my_function(*args, **kwargs):
46
64
47
65
References
48
66
----------
49
- .. [1 ] https://numpydoc.readthedocs.io
67
+ .. [3 ] https://numpydoc.readthedocs.io
50
68
"""
51
69
return None
You can’t perform that action at this time.
0 commit comments