Skip to content

Commit 45b63c4

Browse files
committed
Extend autosum test
With basic test that autosum can include inherited attributes
1 parent 3448f3f commit 45b63c4

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from autosummary_dummy_module import Foo
2+
3+
4+
class InheritedAttrClass(Foo):
5+
6+
def __init__(self):
7+
#: other docstring
8+
self.subclassattr = "subclassattr"
9+
10+
super().__init__()
11+
12+
13+
__all__ = ["InheritedAttrClass"]

tests/roots/test-ext-autosummary/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
autosummary_dummy_module.Foo.value
1414
autosummary_dummy_module.bar
1515
autosummary_dummy_module.qux
16+
autosummary_dummy_inherited_module.InheritedAttrClass
17+
autosummary_dummy_inherited_module.InheritedAttrClass.subclassattr
1618
autosummary_importfail

tests/test_ext_autosummary.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,33 @@ def test_autosummary_generate_content_for_module_imported_members(app):
306306
assert context['objtype'] == 'module'
307307

308308

309+
@pytest.mark.sphinx(testroot='ext-autosummary')
310+
def test_autosummary_generate_content_for_module_imported_members_inherited_module(app):
311+
import autosummary_dummy_inherited_module
312+
template = Mock()
313+
314+
generate_autosummary_content('autosummary_dummy_inherited_module',
315+
autosummary_dummy_inherited_module, None,
316+
template, None, True, app, False, {})
317+
assert template.render.call_args[0][0] == 'module'
318+
319+
context = template.render.call_args[0][1]
320+
assert context['members'] == ['Foo', 'InheritedAttrClass', '__all__', '__builtins__', '__cached__',
321+
'__doc__', '__file__', '__loader__', '__name__',
322+
'__package__', '__spec__']
323+
assert context['functions'] == []
324+
assert context['classes'] == ['Foo', 'InheritedAttrClass']
325+
assert context['exceptions'] == []
326+
assert context['all_exceptions'] == []
327+
assert context['attributes'] == []
328+
assert context['all_attributes'] == []
329+
assert context['fullname'] == 'autosummary_dummy_inherited_module'
330+
assert context['module'] == 'autosummary_dummy_inherited_module'
331+
assert context['objname'] == ''
332+
assert context['name'] == ''
333+
assert context['objtype'] == 'module'
334+
335+
309336
@pytest.mark.sphinx('dummy', testroot='ext-autosummary')
310337
def test_autosummary_generate(app, status, warning):
311338
app.builder.build_all()
@@ -324,16 +351,20 @@ def test_autosummary_generate(app, status, warning):
324351
nodes.row,
325352
nodes.row,
326353
nodes.row,
354+
nodes.row,
355+
nodes.row,
327356
nodes.row)])])
328357
assert_node(doctree[4][0], addnodes.toctree, caption="An autosummary")
329358

330-
assert len(doctree[3][0][0][2]) == 6
359+
assert len(doctree[3][0][0][2]) == 8
331360
assert doctree[3][0][0][2][0].astext() == 'autosummary_dummy_module\n\n'
332361
assert doctree[3][0][0][2][1].astext() == 'autosummary_dummy_module.Foo()\n\n'
333362
assert doctree[3][0][0][2][2].astext() == 'autosummary_dummy_module.Foo.Bar()\n\n'
334363
assert doctree[3][0][0][2][3].astext() == 'autosummary_dummy_module.Foo.value\n\ndocstring'
335364
assert doctree[3][0][0][2][4].astext() == 'autosummary_dummy_module.bar(x[, y])\n\n'
336365
assert doctree[3][0][0][2][5].astext() == 'autosummary_dummy_module.qux\n\na module-level attribute'
366+
assert doctree[3][0][0][2][6].astext() == 'autosummary_dummy_inherited_module.InheritedAttrClass()\n\n'
367+
assert doctree[3][0][0][2][7].astext() == 'autosummary_dummy_inherited_module.InheritedAttrClass.subclassattr\n\nother docstring'
337368

338369
module = (app.srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
339370

@@ -379,6 +410,28 @@ def test_autosummary_generate(app, status, warning):
379410
'\n'
380411
'.. autodata:: qux' in qux)
381412

413+
InheritedAttrClass = (app.srcdir / 'generated' / 'autosummary_dummy_inherited_module.InheritedAttrClass.rst').read_text(encoding='utf8')
414+
print(InheritedAttrClass)
415+
assert '.. automethod:: __init__' in Foo
416+
assert (' .. autosummary::\n'
417+
' \n'
418+
' ~InheritedAttrClass.__init__\n'
419+
' ~InheritedAttrClass.bar\n'
420+
' \n' in InheritedAttrClass)
421+
assert (' .. autosummary::\n'
422+
' \n'
423+
' ~InheritedAttrClass.CONSTANT3\n'
424+
' ~InheritedAttrClass.CONSTANT4\n'
425+
' ~InheritedAttrClass.baz\n'
426+
' ~InheritedAttrClass.subclassattr\n'
427+
' ~InheritedAttrClass.value\n'
428+
' \n' in InheritedAttrClass)
429+
430+
InheritedAttrClass_subclassattr = (app.srcdir / 'generated' / 'autosummary_dummy_inherited_module.InheritedAttrClass.subclassattr.rst').read_text(encoding='utf8')
431+
assert ('.. currentmodule:: autosummary_dummy_inherited_module\n'
432+
'\n'
433+
'.. autoattribute:: InheritedAttrClass.subclassattr' in InheritedAttrClass_subclassattr)
434+
382435

383436
@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
384437
confoverrides={'autosummary_generate_overwrite': False})

0 commit comments

Comments
 (0)