Skip to content

Commit b4c5fd1

Browse files
authored
TST: Add inherited method (#260)
* TST: Add inherited method * FIX: Check version * FIX: Simpler * FIX: Simplify * FIX: Old Sphinx
1 parent 7c42883 commit b4c5fd1

File tree

8 files changed

+25
-13
lines changed

8 files changed

+25
-13
lines changed

numpydoc/numpydoc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def mangle_docstrings(app, what, name, obj, options, lines):
168168
doc = get_doc_object(obj, what, u_NL.join(lines), config=cfg,
169169
builder=app.builder)
170170
lines[:] = str(doc).split(u_NL)
171-
except:
171+
except Exception:
172172
logger.error('[numpydoc] While processing docstring for %r', name)
173173
raise
174174

numpydoc/tests/test_full.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
from distutils.version import LooseVersion
12
import os.path as op
23
import re
34
import shutil
45

56
import pytest
7+
import sphinx
68
from sphinx.application import Sphinx
79
from sphinx.util.docutils import docutils_namespace
810

@@ -25,9 +27,12 @@ def ignore(src, names):
2527
toctrees_dir = op.join(temp_dir, '_build', 'toctrees')
2628
# Avoid warnings about re-registration, see:
2729
# https://github.com/sphinx-doc/sphinx/issues/5038
30+
kwargs = dict()
31+
if LooseVersion(sphinx.__version__) >= LooseVersion('1.8'):
32+
kwargs.update(warningiserror=True, keep_going=True)
2833
with docutils_namespace():
2934
app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir,
30-
buildername='html')
35+
buildername='html', **kwargs)
3136
# need to build within the context manager
3237
# for automodule and backrefs to work
3338
app.build(False, [])
@@ -46,6 +51,9 @@ def test_MyClass(sphinx_app):
4651
'numpydoc_test_module.MyClass.html')
4752
with open(class_html, 'r') as fid:
4853
html = fid.read()
54+
# ensure that no autodoc weirdness ($) occurs
55+
assert '$self' not in html
56+
assert '__init__' in html # inherited
4957
# escaped * chars should no longer be preceded by \'s,
5058
# if we see a \* in the output we know it's incorrect:
5159
assert r'\*' not in html
@@ -77,7 +85,7 @@ def test_reference(sphinx_app):
7785
["generated", "numpydoc_test_module.MyClass.html"],
7886
]
7987

80-
expected_lengths = [3, 1, 1]
88+
expected_lengths = [1, 1, 1]
8189

8290
for html_file, expected_length in zip(html_files, expected_lengths):
8391
html_file = op.join(out_dir, *html_file)

numpydoc/tests/test_validate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,10 @@ def test_bad_generic_functions(self, capsys, func):
12741274
],
12751275
)
12761276
def test_bad_docstrings(self, capsys, klass, func, msgs):
1277-
result = validate_one(self._import_path(klass=klass, func=func))
1277+
with pytest.warns(None) as w:
1278+
result = validate_one(self._import_path(klass=klass, func=func))
1279+
if len(w):
1280+
assert all('Unknown section' in str(ww.message) for ww in w)
12781281
for msg in msgs:
12791282
assert msg in " ".join(err[1] for err in result["errors"])
12801283

numpydoc/tests/tinybuild/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ clean:
55
rm -rf generated/
66

77
html:
8-
sphinx-build -b html -d _build/doctrees . _build/html
8+
sphinx-build -nWT --keep-going -b html -d _build/doctrees . _build/html
99

1010
show:
1111
@python -c "import webbrowser; webbrowser.open_new_tab('file://$(PWD)/_build/html/index.html')"

numpydoc/tests/tinybuild/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
]
1212
project = 'numpydoc_test_module'
1313
autosummary_generate = True
14+
autodoc_default_options = {'inherited-members': None}
1415
source_suffix = '.rst'
1516
master_doc = 'index'
1617
exclude_patterns = ['_build']
@@ -19,4 +20,5 @@
1920
}
2021
nitpicky = True
2122
highlight_language = 'python3'
23+
numpydoc_class_members_toctree = False
2224
numpydoc_xref_param_type = True

numpydoc/tests/tinybuild/index.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ numpydoc_test_module
22
====================
33

44
.. automodule:: numpydoc_test_module
5-
:members:
5+
:no-members:
6+
:no-inherited-members:
7+
:no-special-members:

numpydoc/tests/tinybuild/numpydoc_test_module.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
References
1414
----------
1515
.. [1] https://numpydoc.readthedocs.io
16-
1716
"""
1817

1918
__all__ = ['MyClass', 'my_function']
@@ -36,12 +35,8 @@ class MyClass(object):
3635
.. [2] https://numpydoc.readthedocs.io
3736
"""
3837

39-
def __init__(self, *args, **kwargs):
40-
pass
41-
42-
def example(self):
43-
"""Exampel function
44-
"""
38+
def example(self, x):
39+
"""Example method."""
4540
pass
4641

4742

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
addopts =
33
--showlocals --doctest-modules -ra --cov-report= --cov=numpydoc
44
--junit-xml=junit-results.xml --ignore=doc/conf.py
5+
junit_family = xunit2
56
filterwarnings =
67
ignore:'U' mode is deprecated:DeprecationWarning
8+
ignore:.*sphinx\.util\.smartypants is deprecated.*:
79
ignore:Using or importing the ABCs.*:DeprecationWarning

0 commit comments

Comments
 (0)