Skip to content

Commit

Permalink
Fix #3900: autosummary could not find methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jul 2, 2017
1 parent 82adedb commit b3e0e29
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
5 changes: 4 additions & 1 deletion sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ def get_members(obj, typ, include_public=[], imported=False):
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('_')]
Expand Down
9 changes: 9 additions & 0 deletions tests/roots/test-ext-autosummary/autodoc_dummy_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from os import *


class Foo:
def __init__(self):
pass

def bar(self):
pass
9 changes: 9 additions & 0 deletions tests/roots/test-ext-autosummary/conf.py
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 6 additions & 0 deletions tests/roots/test-ext-autosummary/contents.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

.. autosummary::
:toctree: generated

autodoc_dummy_module
autodoc_dummy_module.Foo
19 changes: 19 additions & 0 deletions tests/test_ext_autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b3e0e29

Please sign in to comment.