Fix #3900: autosummary could not find methods

This commit is contained in:
Takeshi KOMIYA
2017-07-02 18:26:41 +09:00
parent 82adedbc56
commit b3e0e29f4c
6 changed files with 48 additions and 1 deletions

View File

@@ -45,6 +45,7 @@ Bugs fixed
setting.
* #3840: make checking ``epub_uid`` strict
* #3851, #3706: Fix about box drawing characters for PDF output
* #3900: autosummary could not find methods
Testing
--------

View File

@@ -195,7 +195,10 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
continue
documenter = get_documenter(value, obj)
if documenter.objtype == typ:
if imported or getattr(value, '__module__', None) == obj.__name__:
if typ == 'method':
items.append(name)
elif imported or getattr(value, '__module__', None) == obj.__name__:
# skip imported members if expected
items.append(name)
public = [x for x in items
if x in include_public or not x.startswith('_')]

View File

@@ -0,0 +1,9 @@
from os import *
class Foo:
def __init__(self):
pass
def bar(self):
pass

View File

@@ -0,0 +1,9 @@
import sys, os
sys.path.insert(0, os.path.abspath('.'))
extensions = ['sphinx.ext.autosummary']
autosummary_generate = True
# The suffix of source filenames.
source_suffix = '.rst'

View File

@@ -0,0 +1,6 @@
.. autosummary::
:toctree: generated
autodoc_dummy_module
autodoc_dummy_module.Foo

View File

@@ -126,3 +126,22 @@ def test_escaping(app, status, warning):
title = etree_parse(docpage).find('section/title')
assert str_content(title) == 'underscore_module_'
@pytest.mark.sphinx('dummy', testroot='ext-autosummary')
def test_autosummary_generate(app, status, warning):
app.builder.build_all()
module = (app.srcdir / 'generated' / 'autodoc_dummy_module.rst').text()
assert (' .. autosummary::\n'
' \n'
' Foo\n'
' \n' in module)
Foo = (app.srcdir / 'generated' / 'autodoc_dummy_module.Foo.rst').text()
assert '.. automethod:: __init__' in Foo
assert (' .. autosummary::\n'
' \n'
' ~Foo.__init__\n'
' ~Foo.bar\n'
' \n' in Foo)