From 6f55433304e738739b6abfb041e735b2257d8f12 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 19 Apr 2020 11:57:12 -0400 Subject: [PATCH 1/5] TST: Add inherited method --- numpydoc/numpydoc.py | 2 +- numpydoc/tests/test_full.py | 8 ++++++-- numpydoc/tests/test_validate.py | 5 ++++- numpydoc/tests/tinybuild/Makefile | 2 +- numpydoc/tests/tinybuild/conf.py | 5 ++++- numpydoc/tests/tinybuild/index.rst | 4 +++- numpydoc/tests/tinybuild/numpydoc_test_module.py | 13 +++++++++---- setup.cfg | 2 ++ 8 files changed, 30 insertions(+), 11 deletions(-) diff --git a/numpydoc/numpydoc.py b/numpydoc/numpydoc.py index b7d10de9..652eedc6 100644 --- a/numpydoc/numpydoc.py +++ b/numpydoc/numpydoc.py @@ -168,7 +168,7 @@ def mangle_docstrings(app, what, name, obj, options, lines): doc = get_doc_object(obj, what, u_NL.join(lines), config=cfg, builder=app.builder) lines[:] = str(doc).split(u_NL) - except: + except Exception: logger.error('[numpydoc] While processing docstring for %r', name) raise diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index 73837759..c9ebca88 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -27,7 +27,8 @@ def ignore(src, names): # https://github.com/sphinx-doc/sphinx/issues/5038 with docutils_namespace(): app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir, - buildername='html') + buildername='html', warningiserror=True, + keep_going=True) # need to build within the context manager # for automodule and backrefs to work app.build(False, []) @@ -46,6 +47,9 @@ def test_MyClass(sphinx_app): 'numpydoc_test_module.MyClass.html') with open(class_html, 'r') as fid: html = fid.read() + # ensure that no autodoc weirdness ($) occurs + assert '$self' not in html + assert 'Inherit a method' in html # escaped * chars should no longer be preceded by \'s, # if we see a \* in the output we know it's incorrect: assert r'\*' not in html @@ -77,7 +81,7 @@ def test_reference(sphinx_app): ["generated", "numpydoc_test_module.MyClass.html"], ] - expected_lengths = [3, 1, 1] + expected_lengths = [1, 1, 1] for html_file, expected_length in zip(html_files, expected_lengths): html_file = op.join(out_dir, *html_file) diff --git a/numpydoc/tests/test_validate.py b/numpydoc/tests/test_validate.py index ec2bbc9b..b7127ce2 100644 --- a/numpydoc/tests/test_validate.py +++ b/numpydoc/tests/test_validate.py @@ -1274,7 +1274,10 @@ def test_bad_generic_functions(self, capsys, func): ], ) def test_bad_docstrings(self, capsys, klass, func, msgs): - result = validate_one(self._import_path(klass=klass, func=func)) + with pytest.warns(None) as w: + result = validate_one(self._import_path(klass=klass, func=func)) + if len(w): + assert all('Unknown section' in str(ww.message) for ww in w) for msg in msgs: assert msg in " ".join(err[1] for err in result["errors"]) diff --git a/numpydoc/tests/tinybuild/Makefile b/numpydoc/tests/tinybuild/Makefile index 27af0eb3..95d39af2 100644 --- a/numpydoc/tests/tinybuild/Makefile +++ b/numpydoc/tests/tinybuild/Makefile @@ -5,7 +5,7 @@ clean: rm -rf generated/ html: - sphinx-build -b html -d _build/doctrees . _build/html + sphinx-build -nWT --keep-going -b html -d _build/doctrees . _build/html show: @python -c "import webbrowser; webbrowser.open_new_tab('file://$(PWD)/_build/html/index.html')" diff --git a/numpydoc/tests/tinybuild/conf.py b/numpydoc/tests/tinybuild/conf.py index 71ef6640..e53d028d 100644 --- a/numpydoc/tests/tinybuild/conf.py +++ b/numpydoc/tests/tinybuild/conf.py @@ -11,12 +11,15 @@ ] project = 'numpydoc_test_module' autosummary_generate = True +autodoc_default_options = {'inherited-members': None} source_suffix = '.rst' master_doc = 'index' -exclude_patterns = ['_build'] +templates_path = ['_templates'] +exclude_patterns = ['_build', '_templates'] intersphinx_mapping = { 'python': ('https://docs.python.org/3', None), } nitpicky = True highlight_language = 'python3' +numpydoc_class_members_toctree = False numpydoc_xref_param_type = True diff --git a/numpydoc/tests/tinybuild/index.rst b/numpydoc/tests/tinybuild/index.rst index 9d5c1d9c..25a32d41 100644 --- a/numpydoc/tests/tinybuild/index.rst +++ b/numpydoc/tests/tinybuild/index.rst @@ -2,4 +2,6 @@ numpydoc_test_module ==================== .. automodule:: numpydoc_test_module - :members: + :no-members: + :no-inherited-members: + :no-special-members: diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 3c23dc4c..68c2c3c5 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -13,13 +13,19 @@ References ---------- .. [1] https://numpydoc.readthedocs.io - """ __all__ = ['MyClass', 'my_function'] -class MyClass(object): +class _MyBaseClass(object): + + def inherited(self): + """Inherit a method.""" + pass + + +class MyClass(_MyBaseClass): """A class. Reference [2]_ @@ -40,8 +46,7 @@ def __init__(self, *args, **kwargs): pass def example(self): - """Exampel function - """ + """Example function.""" pass diff --git a/setup.cfg b/setup.cfg index 5221732a..420fc78a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,6 +2,8 @@ addopts = --showlocals --doctest-modules -ra --cov-report= --cov=numpydoc --junit-xml=junit-results.xml --ignore=doc/conf.py +junit_family = xunit2 filterwarnings = ignore:'U' mode is deprecated:DeprecationWarning + ignore:.*sphinx\.util\.smartypants is deprecated.*: ignore:Using or importing the ABCs.*:DeprecationWarning From 3b8c8bb294966a9941c36c639588facb1bafaabf Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 19 Apr 2020 19:35:31 -0400 Subject: [PATCH 2/5] FIX: Check version --- 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 c9ebca88..ac087e72 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -1,8 +1,10 @@ +from distutils.version import LooseVersion import os.path as op import re import shutil import pytest +import sphinx from sphinx.application import Sphinx from sphinx.util.docutils import docutils_namespace @@ -25,10 +27,12 @@ def ignore(src, names): toctrees_dir = op.join(temp_dir, '_build', 'toctrees') # Avoid warnings about re-registration, see: # https://github.com/sphinx-doc/sphinx/issues/5038 + kwargs = dict() + if LooseVersion(sphinx.__version__) >= LooseVersion('1.8'): + kwargs.update(warningiserror=True, keep_going=True) with docutils_namespace(): app = Sphinx(src_dir, conf_dir, out_dir, toctrees_dir, - buildername='html', warningiserror=True, - keep_going=True) + buildername='html', **kwargs) # need to build within the context manager # for automodule and backrefs to work app.build(False, []) From cf7c1b0a2d2172a9e5e766678ef551439456da15 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 19 Apr 2020 21:20:27 -0400 Subject: [PATCH 3/5] FIX: Simpler --- numpydoc/tests/test_full.py | 2 +- numpydoc/tests/tinybuild/numpydoc_test_module.py | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/numpydoc/tests/test_full.py b/numpydoc/tests/test_full.py index ac087e72..b727cde5 100644 --- a/numpydoc/tests/test_full.py +++ b/numpydoc/tests/test_full.py @@ -53,7 +53,7 @@ def test_MyClass(sphinx_app): html = fid.read() # ensure that no autodoc weirdness ($) occurs assert '$self' not in html - assert 'Inherit a method' in html + assert '__init__' in html # inherited # escaped * chars should no longer be preceded by \'s, # if we see a \* in the output we know it's incorrect: assert r'\*' not in html diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 68c2c3c5..9459cb3a 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -18,14 +18,7 @@ __all__ = ['MyClass', 'my_function'] -class _MyBaseClass(object): - - def inherited(self): - """Inherit a method.""" - pass - - -class MyClass(_MyBaseClass): +class MyClass(object): """A class. Reference [2]_ @@ -42,9 +35,6 @@ class MyClass(_MyBaseClass): .. [2] https://numpydoc.readthedocs.io """ - def __init__(self, *args, **kwargs): - pass - def example(self): """Example function.""" pass From 83da36af333d5c3a54e1c73030186ecb334f8dd6 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 19 Apr 2020 21:24:28 -0400 Subject: [PATCH 4/5] FIX: Simplify --- numpydoc/tests/tinybuild/conf.py | 3 +-- numpydoc/tests/tinybuild/numpydoc_test_module.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/numpydoc/tests/tinybuild/conf.py b/numpydoc/tests/tinybuild/conf.py index e53d028d..8b16cdd2 100644 --- a/numpydoc/tests/tinybuild/conf.py +++ b/numpydoc/tests/tinybuild/conf.py @@ -14,8 +14,7 @@ autodoc_default_options = {'inherited-members': None} source_suffix = '.rst' master_doc = 'index' -templates_path = ['_templates'] -exclude_patterns = ['_build', '_templates'] +exclude_patterns = ['_build'] intersphinx_mapping = { 'python': ('https://docs.python.org/3', None), } diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 9459cb3a..773f8695 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -36,7 +36,7 @@ class MyClass(object): """ def example(self): - """Example function.""" + """Example method.""" pass From b5db398a7c7b559a2fd2b9101ded3cb60759fd40 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 19 Apr 2020 21:42:05 -0400 Subject: [PATCH 5/5] FIX: Old Sphinx --- numpydoc/tests/tinybuild/numpydoc_test_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/numpydoc/tests/tinybuild/numpydoc_test_module.py b/numpydoc/tests/tinybuild/numpydoc_test_module.py index 773f8695..3c073dff 100644 --- a/numpydoc/tests/tinybuild/numpydoc_test_module.py +++ b/numpydoc/tests/tinybuild/numpydoc_test_module.py @@ -35,7 +35,7 @@ class MyClass(object): .. [2] https://numpydoc.readthedocs.io """ - def example(self): + def example(self, x): """Example method.""" pass