summaryrefslogtreecommitdiff
path: root/tests/test_autodoc.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-12 01:42:05 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-02-12 01:42:05 +0900
commitc5f0025ed9aacb05e320780fe5ccc8a60c3483e5 (patch)
treee8dfe0c82246a3a3c3172098234a00b92bd09dca /tests/test_autodoc.py
parent27376912122342875d9db4e65c08d084c645cece (diff)
parent0adf058916b7bd3a1df6f480c73792d035e5f693 (diff)
downloadsphinx-git-c5f0025ed9aacb05e320780fe5ccc8a60c3483e5.tar.gz
Merge branch 'master' into 5637
Diffstat (limited to 'tests/test_autodoc.py')
-rw-r--r--tests/test_autodoc.py947
1 files changed, 377 insertions, 570 deletions
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index 7e278459d..e6b4cc5b6 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -5,21 +5,18 @@
Test the autodoc extension. This tests mainly the Documenters; the auto
directives are tested in a test source file translated by test_build.
- :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-import platform
import sys
+from unittest.mock import Mock
from warnings import catch_warnings
import pytest
from docutils.statemachine import ViewList
-from sphinx.ext.autodoc import (
- ModuleLevelDocumenter, cut_lines, between, ALL,
- merge_autodoc_default_flags, Options
-)
+from sphinx.ext.autodoc import ModuleLevelDocumenter, ALL, Options
from sphinx.ext.autodoc.directive import DocumenterBridge, process_documenter_options
from sphinx.testing.util import SphinxTestApp, Struct # NOQA
from sphinx.util import logging
@@ -27,8 +24,6 @@ from sphinx.util.docutils import LoggingReporter
app = None
-IS_PYPY = platform.python_implementation() == 'PyPy'
-
def do_autodoc(app, objtype, name, options=None):
if options is None:
@@ -36,7 +31,9 @@ def do_autodoc(app, objtype, name, options=None):
app.env.temp_data.setdefault('docname', 'index') # set dummy docname
doccls = app.registry.documenters[objtype]
docoptions = process_documenter_options(doccls, app.config, options)
- bridge = DocumenterBridge(app.env, LoggingReporter(''), docoptions, 1)
+ state = Mock()
+ state.document.settings.tab_width = 8
+ bridge = DocumenterBridge(app.env, LoggingReporter(''), docoptions, 1, state)
documenter = doccls(bridge, name)
documenter.generate()
@@ -55,7 +52,6 @@ def setup_module(rootdir, sphinx_test_tempdir):
app = SphinxTestApp(srcdir=srcdir)
app.builder.env.app = app
app.builder.env.temp_data['docname'] = 'dummy'
- app.connect('autodoc-process-docstring', process_docstring)
app.connect('autodoc-process-signature', process_signature)
app.connect('autodoc-skip-member', skip_member)
yield
@@ -70,7 +66,7 @@ directive = options = None
@pytest.fixture
def setup_test():
global options, directive
- global processed_docstrings, processed_signatures
+ global processed_signatures
options = Options(
inherited_members = False,
@@ -95,9 +91,10 @@ def setup_test():
genopt = options,
result = ViewList(),
filename_set = set(),
+ state = Mock(),
)
+ directive.state.document.settings.tab_width = 8
- processed_docstrings = []
processed_signatures = []
app._status.truncate(0)
@@ -108,16 +105,9 @@ def setup_test():
app.registry.autodoc_attrgettrs.clear()
-processed_docstrings = []
processed_signatures = []
-def process_docstring(app, what, name, obj, options, lines):
- processed_docstrings.append((what, name))
- if name == 'bar':
- lines.extend(['42', ''])
-
-
def process_signature(app, what, name, obj, options, args, retann):
processed_signatures.append((what, name))
if name == 'bar':
@@ -259,6 +249,11 @@ def test_format_signature():
assert formatsig('method', 'H.foo', H.foo2, None, None) == '(*c)'
assert formatsig('method', 'H.foo', H.foo3, None, None) == r"(d='\\n')"
+ # test bound methods interpreted as functions
+ assert formatsig('function', 'foo', H().foo1, None, None) == '(b, *c)'
+ assert formatsig('function', 'foo', H().foo2, None, None) == '(*c)'
+ assert formatsig('function', 'foo', H().foo3, None, None) == r"(d='\\n')"
+
# test exception handling (exception is caught and args is '')
directive.env.config.autodoc_docstring_signature = False
assert formatsig('function', 'int', int, None, None) == ''
@@ -330,190 +325,13 @@ def test_get_doc():
"""Döcstring"""
assert getdocl('function', f) == ['Döcstring']
- # class docstring: depends on config value which one is taken
- class C:
- """Class docstring"""
- def __init__(self):
- """Init docstring"""
-
- def __new__(cls):
- """New docstring"""
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', C) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', C) == ['Init docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', C) == ['Class docstring', '', 'Init docstring']
-
- class D:
- """Class docstring"""
- def __init__(self):
- """Init docstring
-
- Other
- lines
- """
-
- # Indentation is normalized for 'both'
- assert getdocl('class', D) == ['Class docstring', '', 'Init docstring',
- '', 'Other', ' lines']
-
- # __init__ have signature at first line of docstring
- class E:
- """Class docstring"""
- def __init__(self, *args, **kw):
- """
- __init__(a1, a2, kw1=True, kw2=False)
-
- Init docstring
- """
-
- # signature line in the docstring will be kept when
- # autodoc_docstring_signature == False
- directive.env.config.autodoc_docstring_signature = False
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', E) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', E) == ['__init__(a1, a2, kw1=True, kw2=False)',
- '', 'Init docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', E) == ['Class docstring', '',
- '__init__(a1, a2, kw1=True, kw2=False)',
- '', 'Init docstring']
-
- # signature line in the docstring will be removed when
- # autodoc_docstring_signature == True
- directive.env.config.autodoc_docstring_signature = True # default
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', E) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', E) == ['Init docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', E) == ['Class docstring', '', 'Init docstring']
-
- # class does not have __init__ method
- class F:
- """Class docstring"""
-
- # docstring in the __init__ method of base class will be discard
- for f in (False, True):
- directive.env.config.autodoc_docstring_signature = f
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', F) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', F) == ['Class docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', F) == ['Class docstring']
-
- # class has __init__ method with no docstring
- class G:
- """Class docstring"""
- def __init__(self):
- pass
-
- # docstring in the __init__ method of base class will not be used
- for f in (False, True):
- directive.env.config.autodoc_docstring_signature = f
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', G) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', G) == ['Class docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', G) == ['Class docstring']
-
- # class has __new__ method with docstring
- # class docstring: depends on config value which one is taken
- class H:
- """Class docstring"""
- def __init__(self):
- pass
-
- def __new__(cls):
- """New docstring"""
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', H) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', H) == ['New docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', H) == ['Class docstring', '', 'New docstring']
-
- # class has __init__ method without docstring and
- # __new__ method with docstring
- # class docstring: depends on config value which one is taken
- class I: # NOQA
- """Class docstring"""
- def __new__(cls):
- """New docstring"""
- directive.env.config.autoclass_content = 'class'
- assert getdocl('class', I) == ['Class docstring']
- directive.env.config.autoclass_content = 'init'
- assert getdocl('class', I) == ['New docstring']
- directive.env.config.autoclass_content = 'both'
- assert getdocl('class', I) == ['Class docstring', '', 'New docstring']
-
- from target import Base, Derived
-
- # NOTE: inspect.getdoc seems not to work with locally defined classes
- directive.env.config.autodoc_inherit_docstrings = False
- assert getdocl('method', Base.inheritedmeth) == ['Inherited function.']
- assert getdocl('method', Derived.inheritedmeth) == []
- directive.env.config.autodoc_inherit_docstrings = True
- assert getdocl('method', Derived.inheritedmeth) == ['Inherited function.']
-
-
-@pytest.mark.usefixtures('setup_test')
-def test_docstring_processing():
- def process(objtype, name, obj):
- inst = app.registry.documenters[objtype](directive, name)
- inst.object = obj
- inst.fullname = name
- return list(inst.process_doc(inst.get_doc()))
-
- class E:
- def __init__(self):
- """Init docstring"""
-
- # docstring processing by event handler
- assert process('class', 'bar', E) == ['Init docstring', '', '42', '']
-
- lid = app.connect('autodoc-process-docstring',
- cut_lines(1, 1, ['function']))
-
- def f():
- """
- first line
- second line
- third line
- """
- assert process('function', 'f', f) == ['second line', '']
- app.disconnect(lid)
-
- lid = app.connect('autodoc-process-docstring', between('---', ['function']))
-
- def g():
- """
- first line
- ---
- second line
- ---
- third line
- """
- assert process('function', 'g', g) == ['second line', '']
- app.disconnect(lid)
-
- lid = app.connect('autodoc-process-docstring',
- between('---', ['function'], exclude=True))
-
- def h():
- """
- first line
- ---
- second line
- ---
- third line
- """
- assert process('function', 'h', h) == ['first line', 'third line', '']
- app.disconnect(lid)
+ # verify that method docstrings get extracted in both normal case
+ # and in case of bound method posing as a function
+ class J: # NOQA
+ def foo(self):
+ """Method docstring"""
+ assert getdocl('method', J.foo) == ['Method docstring']
+ assert getdocl('function', J().foo) == ['Method docstring']
@pytest.mark.sphinx('html', testroot='ext-autodoc')
@@ -550,6 +368,7 @@ def test_new_documenter(app):
@pytest.mark.usefixtures('setup_test')
def test_attrgetter_using():
from target import Class
+ from target.inheritance import Derived
def assert_getter_works(objtype, name, obj, attrs=[], **kw):
getattr_spy = []
@@ -579,7 +398,7 @@ def test_attrgetter_using():
assert_getter_works('class', 'target.Class', Class, ['meth'])
options.inherited_members = True
- assert_getter_works('class', 'target.Class', Class, ['meth', 'inheritedmeth'])
+ assert_getter_works('class', 'target.inheritance.Derived', Derived, ['inheritedmeth'])
@pytest.mark.sphinx('html', testroot='ext-autodoc')
@@ -682,28 +501,28 @@ def test_autodoc_attributes(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_members(app):
# default (no-members)
- actual = do_autodoc(app, 'class', 'target.Base')
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base')
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Base',
]
# default ALL-members
options = {"members": None}
- actual = do_autodoc(app, 'class', 'target.Base', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Base',
- ' .. py:classmethod:: Base.inheritedclassmeth()',
+ ' .. py:method:: Base.inheritedclassmeth()',
' .. py:method:: Base.inheritedmeth()',
- ' .. py:staticmethod:: Base.inheritedstaticmeth(cls)'
+ ' .. py:method:: Base.inheritedstaticmeth(cls)'
]
# default specific-members
options = {"members": "inheritedmeth,inheritedstaticmeth"}
- actual = do_autodoc(app, 'class', 'target.Base', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Base',
' .. py:method:: Base.inheritedmeth()',
- ' .. py:staticmethod:: Base.inheritedstaticmeth(cls)'
+ ' .. py:method:: Base.inheritedstaticmeth(cls)'
]
@@ -711,16 +530,16 @@ def test_autodoc_members(app):
def test_autodoc_exclude_members(app):
options = {"members": None,
"exclude-members": "inheritedmeth,inheritedstaticmeth"}
- actual = do_autodoc(app, 'class', 'target.Base', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Base',
- ' .. py:classmethod:: Base.inheritedclassmeth()'
+ ' .. py:method:: Base.inheritedclassmeth()'
]
# members vs exclude-members
options = {"members": "inheritedmeth",
"exclude-members": "inheritedmeth"}
- actual = do_autodoc(app, 'class', 'target.Base', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Base',
]
@@ -734,7 +553,6 @@ def test_autodoc_undoc_members(app):
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Class(arg)',
' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.descr',
' .. py:attribute:: Class.docattr',
' .. py:method:: Class.excludemeth()',
' .. py:attribute:: Class.inst_attr_comment',
@@ -742,9 +560,8 @@ def test_autodoc_undoc_members(app):
' .. py:attribute:: Class.inst_attr_string',
' .. py:attribute:: Class.mdocattr',
' .. py:method:: Class.meth()',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:attribute:: Class.prop',
- ' .. py:classmethod:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
+ ' .. py:method:: Class.moore(a, e, f) -> happiness',
+ ' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
' .. py:attribute:: Class.skipattr',
' .. py:method:: Class.skipmeth()',
' .. py:attribute:: Class.udocattr',
@@ -756,25 +573,45 @@ def test_autodoc_undoc_members(app):
def test_autodoc_inherited_members(app):
options = {"members": None,
"inherited-members": None}
- actual = do_autodoc(app, 'class', 'target.Class', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Derived', options)
assert list(filter(lambda l: 'method::' in l, actual)) == [
- ' .. py:method:: Class.excludemeth()',
- ' .. py:classmethod:: Class.inheritedclassmeth()',
- ' .. py:method:: Class.inheritedmeth()',
- ' .. py:staticmethod:: Class.inheritedstaticmeth(cls)',
- ' .. py:method:: Class.meth()',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:method:: Class.skipmeth()'
+ ' .. py:method:: Derived.inheritedclassmeth()',
+ ' .. py:method:: Derived.inheritedmeth()',
+ ' .. py:method:: Derived.inheritedstaticmeth(cls)',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_inherited_members_Base(app):
+ options = {"members": None,
+ "inherited-members": "Base",
+ "special-members": None}
+
+ # check methods for object class are shown
+ actual = do_autodoc(app, 'class', 'target.inheritance.Derived', options)
+ assert ' .. py:method:: Derived.inheritedmeth()' in actual
+ assert ' .. py:method:: Derived.inheritedclassmeth' not in actual
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_inherited_members_None(app):
+ options = {"members": None,
+ "inherited-members": "None",
+ "special-members": None}
+
+ # check methods for object class are shown
+ actual = do_autodoc(app, 'class', 'target.inheritance.Derived', options)
+ assert ' .. py:method:: Derived.__init__' in actual
+ assert ' .. py:method:: Derived.__str__' in actual
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_imported_members(app):
options = {"members": None,
"imported-members": None,
"ignore-module-all": None}
actual = do_autodoc(app, 'module', 'target', options)
- assert '.. py:function:: save_traceback(app)' in actual
+ assert '.. py:function:: save_traceback(app: Sphinx) -> str' in actual
@pytest.mark.sphinx('html', testroot='ext-autodoc')
@@ -809,12 +646,13 @@ def test_autodoc_special_members(app):
actual = do_autodoc(app, 'class', 'target.Class', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Class(arg)',
+ ' .. py:attribute:: Class.__dict__',
' .. py:method:: Class.__init__(arg)',
' .. py:attribute:: Class.__module__',
' .. py:method:: Class.__special1__()',
' .. py:method:: Class.__special2__()',
+ ' .. py:attribute:: Class.__weakref__',
' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.descr',
' .. py:attribute:: Class.docattr',
' .. py:method:: Class.excludemeth()',
' .. py:attribute:: Class.inst_attr_comment',
@@ -822,9 +660,8 @@ def test_autodoc_special_members(app):
' .. py:attribute:: Class.inst_attr_string',
' .. py:attribute:: Class.mdocattr',
' .. py:method:: Class.meth()',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:attribute:: Class.prop',
- ' .. py:classmethod:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
+ ' .. py:method:: Class.moore(a, e, f) -> happiness',
+ ' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
' .. py:attribute:: Class.skipattr',
' .. py:method:: Class.skipmeth()',
' .. py:attribute:: Class.udocattr',
@@ -847,9 +684,6 @@ def test_autodoc_ignore_module_all(app):
actual = do_autodoc(app, 'module', 'target', options)
assert list(filter(lambda l: 'class::' in l, actual)) == [
'.. py:class:: Class(arg)',
- '.. py:class:: CustomDataDescriptor(doc)',
- '.. py:class:: CustomDataDescriptor2(doc)',
- '.. py:class:: CustomDataDescriptorMeta',
'.. py:class:: CustomDict',
'.. py:class:: InnerChild',
'.. py:class:: InstAttCls()',
@@ -872,12 +706,12 @@ def test_autodoc_noindex(app):
# TODO: :noindex: should be propagated to children of target item.
- actual = do_autodoc(app, 'class', 'target.Base', options)
+ actual = do_autodoc(app, 'class', 'target.inheritance.Base', options)
assert list(actual) == [
'',
'.. py:class:: Base',
' :noindex:',
- ' :module: target',
+ ' :module: target.inheritance',
''
]
@@ -956,19 +790,60 @@ def test_autodoc_inner_class(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
-def test_autodoc_descriptor(app):
- actual = do_autodoc(app, 'attribute', 'target.Class.descr')
+def test_autodoc_classmethod(app):
+ actual = do_autodoc(app, 'method', 'target.inheritance.Base.inheritedclassmeth')
assert list(actual) == [
'',
- '.. py:attribute:: Class.descr',
- ' :module: target',
+ '.. py:method:: Base.inheritedclassmeth()',
+ ' :module: target.inheritance',
+ ' :classmethod:',
+ '',
+ ' Inherited class method.',
+ ' '
+ ]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_staticmethod(app):
+ actual = do_autodoc(app, 'method', 'target.inheritance.Base.inheritedstaticmeth')
+ assert list(actual) == [
+ '',
+ '.. py:method:: Base.inheritedstaticmeth(cls)',
+ ' :module: target.inheritance',
+ ' :staticmethod:',
'',
- ' Descriptor instance docstring.',
+ ' Inherited static method.',
' '
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_autodoc_descriptor(app):
+ options = {"members": None,
+ "undoc-members": True}
+ actual = do_autodoc(app, 'class', 'target.descriptor.Class', options)
+ assert list(actual) == [
+ '',
+ '.. py:class:: Class',
+ ' :module: target.descriptor',
+ '',
+ ' ',
+ ' .. py:attribute:: Class.descr',
+ ' :module: target.descriptor',
+ ' ',
+ ' Descriptor instance docstring.',
+ ' ',
+ ' ',
+ ' .. py:method:: Class.prop',
+ ' :module: target.descriptor',
+ ' :property:',
+ ' ',
+ ' Property.',
+ ' '
+ ]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_autodoc_c_module(app):
actual = do_autodoc(app, 'function', 'time.asctime')
assert list(actual) == [
@@ -993,19 +868,17 @@ def test_autodoc_member_order(app):
actual = do_autodoc(app, 'class', 'target.Class', options)
assert list(filter(lambda l: '::' in l, actual)) == [
'.. py:class:: Class(arg)',
- ' .. py:attribute:: Class.descr',
' .. py:method:: Class.meth()',
' .. py:method:: Class.undocmeth()',
' .. py:method:: Class.skipmeth()',
' .. py:method:: Class.excludemeth()',
' .. py:attribute:: Class.skipattr',
' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.prop',
' .. py:attribute:: Class.docattr',
' .. py:attribute:: Class.udocattr',
' .. py:attribute:: Class.mdocattr',
- ' .. py:classmethod:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
+ ' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
+ ' .. py:method:: Class.moore(a, e, f) -> happiness',
' .. py:attribute:: Class.inst_attr_inline',
' .. py:attribute:: Class.inst_attr_comment',
' .. py:attribute:: Class.inst_attr_string',
@@ -1022,19 +895,17 @@ def test_autodoc_member_order(app):
'.. py:class:: Class(arg)',
' .. py:method:: Class.excludemeth()',
' .. py:method:: Class.meth()',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:classmethod:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
+ ' .. py:method:: Class.moore(a, e, f) -> happiness',
+ ' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
' .. py:method:: Class.skipmeth()',
' .. py:method:: Class.undocmeth()',
' .. py:attribute:: Class._private_inst_attr',
' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.descr',
' .. py:attribute:: Class.docattr',
' .. py:attribute:: Class.inst_attr_comment',
' .. py:attribute:: Class.inst_attr_inline',
' .. py:attribute:: Class.inst_attr_string',
' .. py:attribute:: Class.mdocattr',
- ' .. py:attribute:: Class.prop',
' .. py:attribute:: Class.skipattr',
' .. py:attribute:: Class.udocattr'
]
@@ -1048,7 +919,6 @@ def test_autodoc_member_order(app):
'.. py:class:: Class(arg)',
' .. py:attribute:: Class._private_inst_attr',
' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.descr',
' .. py:attribute:: Class.docattr',
' .. py:method:: Class.excludemeth()',
' .. py:attribute:: Class.inst_attr_comment',
@@ -1056,9 +926,8 @@ def test_autodoc_member_order(app):
' .. py:attribute:: Class.inst_attr_string',
' .. py:attribute:: Class.mdocattr',
' .. py:method:: Class.meth()',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:attribute:: Class.prop',
- ' .. py:classmethod:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
+ ' .. py:method:: Class.moore(a, e, f) -> happiness',
+ ' .. py:method:: Class.roger(a, *, b=2, c=3, d=4, e=5, f=6)',
' .. py:attribute:: Class.skipattr',
' .. py:method:: Class.skipmeth()',
' .. py:attribute:: Class.udocattr',
@@ -1074,7 +943,7 @@ def test_autodoc_module_scope(app):
'',
'.. py:attribute:: Class.mdocattr',
' :module: target',
- ' :annotation: = <_io.StringIO object>',
+ ' :value: <_io.StringIO object>',
'',
' should be documented as well - süß',
' '
@@ -1090,7 +959,7 @@ def test_autodoc_class_scope(app):
'',
'.. py:attribute:: Class.mdocattr',
' :module: target',
- ' :annotation: = <_io.StringIO object>',
+ ' :value: <_io.StringIO object>',
'',
' should be documented as well - süß',
' '
@@ -1098,91 +967,6 @@ def test_autodoc_class_scope(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
-def test_autodoc_docstring_signature(app):
- options = {"members": None}
- actual = do_autodoc(app, 'class', 'target.DocstringSig', options)
- assert list(actual) == [
- '',
- '.. py:class:: DocstringSig',
- ' :module: target',
- '',
- ' ',
- ' .. py:method:: DocstringSig.meth(FOO, BAR=1) -> BAZ',
- ' :module: target',
- ' ',
- ' First line of docstring',
- ' ',
- ' rest of docstring',
- ' ',
- ' ',
- ' .. py:method:: DocstringSig.meth2()',
- ' :module: target',
- ' ',
- ' First line, no signature',
- ' Second line followed by indentation::',
- ' ',
- ' indented line',
- ' ',
- ' ',
- ' .. py:attribute:: DocstringSig.prop1',
- ' :module: target',
- ' ',
- ' First line of docstring',
- ' ',
- ' ',
- ' .. py:attribute:: DocstringSig.prop2',
- ' :module: target',
- ' ',
- ' First line of docstring',
- ' Second line of docstring',
- ' '
- ]
-
- # disable autodoc_docstring_signature
- app.config.autodoc_docstring_signature = False
- actual = do_autodoc(app, 'class', 'target.DocstringSig', options)
- assert list(actual) == [
- '',
- '.. py:class:: DocstringSig',
- ' :module: target',
- '',
- ' ',
- ' .. py:method:: DocstringSig.meth()',
- ' :module: target',
- ' ',
- ' meth(FOO, BAR=1) -> BAZ',
- ' First line of docstring',
- ' ',
- ' rest of docstring',
- ' ',
- ' ',
- ' ',
- ' .. py:method:: DocstringSig.meth2()',
- ' :module: target',
- ' ',
- ' First line, no signature',
- ' Second line followed by indentation::',
- ' ',
- ' indented line',
- ' ',
- ' ',
- ' .. py:attribute:: DocstringSig.prop1',
- ' :module: target',
- ' ',
- ' DocstringSig.prop1(self)',
- ' First line of docstring',
- ' ',
- ' ',
- ' .. py:attribute:: DocstringSig.prop2',
- ' :module: target',
- ' ',
- ' First line of docstring',
- ' Second line of docstring',
- ' '
- ]
-
-
-@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_class_attributes(app):
options = {"members": None,
"undoc-members": True}
@@ -1195,12 +979,12 @@ def test_class_attributes(app):
' ',
' .. py:attribute:: AttCls.a1',
' :module: target',
- ' :annotation: = hello world',
+ ' :value: hello world',
' ',
' ',
' .. py:attribute:: AttCls.a2',
' :module: target',
- ' :annotation: = None',
+ ' :value: None',
' '
]
@@ -1219,7 +1003,7 @@ def test_instance_attributes(app):
' ',
' .. py:attribute:: InstAttCls.ca1',
' :module: target',
- " :annotation: = 'a'",
+ " :value: 'a'",
' ',
' Doc comment for class attribute InstAttCls.ca1.',
' It can have multiple lines.',
@@ -1227,28 +1011,28 @@ def test_instance_attributes(app):
' ',
' .. py:attribute:: InstAttCls.ca2',
' :module: target',
- " :annotation: = 'b'",
+ " :value: 'b'",
' ',
' Doc comment for InstAttCls.ca2. One line only.',
' ',
' ',
' .. py:attribute:: InstAttCls.ca3',
' :module: target',
- " :annotation: = 'c'",
+ " :value: 'c'",
' ',
' Docstring for class attribute InstAttCls.ca3.',
' ',
' ',
' .. py:attribute:: InstAttCls.ia1',
' :module: target',
- ' :annotation: = None',
+ ' :value: None',
' ',
' Doc comment for instance attribute InstAttCls.ia1',
' ',
' ',
' .. py:attribute:: InstAttCls.ia2',
' :module: target',
- ' :annotation: = None',
+ ' :value: None',
' ',
' Docstring for instance attribute InstAttCls.ia2.',
' '
@@ -1267,7 +1051,7 @@ def test_instance_attributes(app):
' ',
' .. py:attribute:: InstAttCls.ca1',
' :module: target',
- " :annotation: = 'a'",
+ " :value: 'a'",
' ',
' Doc comment for class attribute InstAttCls.ca1.',
' It can have multiple lines.',
@@ -1275,7 +1059,7 @@ def test_instance_attributes(app):
' ',
' .. py:attribute:: InstAttCls.ia1',
' :module: target',
- ' :annotation: = None',
+ ' :value: None',
' ',
' Doc comment for instance attribute InstAttCls.ia1',
' '
@@ -1283,6 +1067,46 @@ def test_instance_attributes(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
+def test_slots(app):
+ options = {"members": None,
+ "undoc-members": True}
+ actual = do_autodoc(app, 'module', 'target.slots', options)
+ assert list(actual) == [
+ '',
+ '.. py:module:: target.slots',
+ '',
+ '',
+ '.. py:class:: Bar()',
+ ' :module: target.slots',
+ '',
+ ' ',
+ ' .. py:attribute:: Bar.attr1',
+ ' :module: target.slots',
+ ' ',
+ ' docstring of attr1',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Bar.attr2',
+ ' :module: target.slots',
+ ' ',
+ ' docstring of instance attr2',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Bar.attr3',
+ ' :module: target.slots',
+ ' ',
+ '',
+ '.. py:class:: Foo',
+ ' :module: target.slots',
+ '',
+ ' ',
+ ' .. py:attribute:: Foo.attr',
+ ' :module: target.slots',
+ ' ',
+ ]
+
+
+@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_enum_class(app):
options = {"members": None,
"undoc-members": True}
@@ -1303,28 +1127,28 @@ def test_enum_class(app):
' ',
' .. py:attribute:: EnumCls.val1',
' :module: target.enum',
- ' :annotation: = 12',
+ ' :value: 12',
' ',
' doc for val1',
' ',
' ',
' .. py:attribute:: EnumCls.val2',
' :module: target.enum',
- ' :annotation: = 23',
+ ' :value: 23',
' ',
' doc for val2',
' ',
' ',
' .. py:attribute:: EnumCls.val3',
' :module: target.enum',
- ' :annotation: = 34',
+ ' :value: 34',
' ',
' doc for val3',
' ',
' ',
' .. py:attribute:: EnumCls.val4',
' :module: target.enum',
- ' :annotation: = 34',
+ ' :value: 34',
' '
]
@@ -1334,7 +1158,7 @@ def test_enum_class(app):
'',
'.. py:attribute:: EnumCls.val1',
' :module: target.enum',
- ' :annotation: = 12',
+ ' :value: 12',
'',
' doc for val1',
' '
@@ -1344,26 +1168,26 @@ def test_enum_class(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_descriptor_class(app):
options = {"members": 'CustomDataDescriptor,CustomDataDescriptor2'}
- actual = do_autodoc(app, 'module', 'target', options)
+ actual = do_autodoc(app, 'module', 'target.descriptor', options)
assert list(actual) == [
'',
- '.. py:module:: target',
+ '.. py:module:: target.descriptor',
'',
'',
'.. py:class:: CustomDataDescriptor(doc)',
- ' :module: target',
+ ' :module: target.descriptor',
'',
' Descriptor class docstring.',
' ',
' ',
' .. py:method:: CustomDataDescriptor.meth()',
- ' :module: target',
+ ' :module: target.descriptor',
' ',
' Function.',
' ',
'',
'.. py:class:: CustomDataDescriptor2(doc)',
- ' :module: target',
+ ' :module: target.descriptor',
'',
' Descriptor class with custom metaclass docstring.',
' '
@@ -1396,55 +1220,53 @@ def test_autofunction_for_method(app):
]
-@pytest.mark.sphinx('html', testroot='ext-autodoc')
-def test_mocked_module_imports(app, warning):
- # no autodoc_mock_imports
- options = {"members": 'TestAutodoc,decoratedFunction,func'}
- actual = do_autodoc(app, 'module', 'target.need_mocks', options)
- assert list(actual) == []
- assert "autodoc: failed to import module 'need_mocks'" in warning.getvalue()
-
- # with autodoc_mock_imports
- app.config.autodoc_mock_imports = [
- 'missing_module',
- 'missing_package1',
- 'missing_package2',
- 'missing_package3',
- 'sphinx.missing_module4',
- ]
-
- warning.truncate(0)
- actual = do_autodoc(app, 'module', 'target.need_mocks', options)
+@pytest.mark.usefixtures('setup_test')
+def test_abstractmethods():
+ options = {"members": None,
+ "undoc-members": None}
+ actual = do_autodoc(app, 'module', 'target.abstractmethods', options)
assert list(actual) == [
'',
- '.. py:module:: target.need_mocks',
+ '.. py:module:: target.abstractmethods',
'',
'',
- '.. py:class:: TestAutodoc',
- ' :module: target.need_mocks',
+ '.. py:class:: Base',
+ ' :module: target.abstractmethods',
'',
- ' TestAutodoc docstring.',
' ',
+ ' .. py:method:: Base.abstractmeth()',
+ ' :module: target.abstractmethods',
+ ' :abstractmethod:',
' ',
- ' .. py:method:: TestAutodoc.decoratedMethod()',
- ' :module: target.need_mocks',
' ',
- ' TestAutodoc::decoratedMethod docstring',
- ' ',
- '',
- '.. py:function:: decoratedFunction()',
- ' :module: target.need_mocks',
- '',
- ' decoratedFunction docstring',
+ ' .. py:method:: Base.classmeth()',
+ ' :module: target.abstractmethods',
+ ' :abstractmethod:',
+ ' :classmethod:',
' ',
- '',
- '.. py:function:: func(arg: missing_module.Class)',
- ' :module: target.need_mocks',
- '',
- ' a function takes mocked object as an argument',
+ ' ',
+ ' .. py:method:: Base.coroutinemeth()',
+ ' :module: target.abstractmethods',
+ ' :abstractmethod:',
+ ' :async:',
+ ' ',
+ ' ',
+ ' .. py:method:: Base.meth()',
+ ' :module: target.abstractmethods',
+ ' ',
+ ' ',
+ ' .. py:method:: Base.prop',
+ ' :module: target.abstractmethods',
+ ' :abstractmethod:',
+ ' :property:',
+ ' ',
+ ' ',
+ ' .. py:method:: Base.staticmeth()',
+ ' :module: target.abstractmethods',
+ ' :abstractmethod:',
+ ' :staticmethod:',
' '
]
- assert warning.getvalue() == ''
@pytest.mark.usefixtures('setup_test')
@@ -1456,19 +1278,25 @@ def test_partialfunction():
'.. py:module:: target.partialfunction',
'',
'',
- '.. py:function:: func1()',
+ '.. py:function:: func1(a, b, c)',
' :module: target.partialfunction',
'',
' docstring of func1',
' ',
'',
- '.. py:function:: func2()',
+ '.. py:function:: func2(b, c)',
' :module: target.partialfunction',
'',
' docstring of func1',
' ',
'',
- '.. py:function:: func3()',
+ '.. py:function:: func3(c)',
+ ' :module: target.partialfunction',
+ '',
+ ' docstring of func3',
+ ' ',
+ '',
+ '.. py:function:: func4()',
' :module: target.partialfunction',
'',
' docstring of func3',
@@ -1477,7 +1305,44 @@ def test_partialfunction():
@pytest.mark.usefixtures('setup_test')
+def test_imported_partialfunction_should_not_shown_without_imported_members():
+ options = {"members": None}
+ actual = do_autodoc(app, 'module', 'target.imported_members', options)
+ assert list(actual) == [
+ '',
+ '.. py:module:: target.imported_members',
+ ''
+ ]
+
+
+@pytest.mark.usefixtures('setup_test')
+def test_bound_method():
+ options = {"members": None}
+ actual = do_autodoc(app, 'module', 'target.bound_method', options)
+ assert list(actual) == [
+ '',
+ '.. py:module:: target.bound_method',
+ '',
+ '',
+ '.. py:function:: bound_method()',
+ ' :module: target.bound_method',
+ '',
+ ' Method docstring',
+ ' ',
+ ]
+
+
+@pytest.mark.usefixtures('setup_test')
def test_coroutine():
+ actual = do_autodoc(app, 'function', 'target.functions.coroutinefunc')
+ assert list(actual) == [
+ '',
+ '.. py:function:: coroutinefunc()',
+ ' :module: target.functions',
+ ' :async:',
+ '',
+ ]
+
options = {"members": None}
actual = do_autodoc(app, 'class', 'target.coroutine.AsyncClass', options)
assert list(actual) == [
@@ -1488,6 +1353,7 @@ def test_coroutine():
' ',
' .. py:method:: AsyncClass.do_coroutine()',
' :module: target.coroutine',
+ ' :async:',
' ',
' A documented coroutine function',
' '
@@ -1506,29 +1372,18 @@ def test_partialmethod(app):
' refs: https://docs.python.jp/3/library/functools.html#functools.partialmethod',
' ',
' ',
- ' .. py:method:: Cell.set_alive() -> None',
+ ' .. py:method:: Cell.set_alive()',
' :module: target.partialmethod',
' ',
' Make a cell alive.',
' ',
' ',
- ' .. py:method:: Cell.set_dead() -> None',
- ' :module: target.partialmethod',
- ' ',
- ' Make a cell dead.',
- ' ',
- ' ',
' .. py:method:: Cell.set_state(state)',
' :module: target.partialmethod',
' ',
' Update state of cell to *state*.',
' ',
]
- if (sys.version_info < (3, 5, 4) or
- (3, 6, 5) <= sys.version_info < (3, 7) or
- (3, 7, 0, 'beta', 3) <= sys.version_info):
- # TODO: this condition should be updated after 3.7-final release.
- expected = '\n'.join(expected).replace(' -> None', '').split('\n')
options = {"members": None}
actual = do_autodoc(app, 'class', 'target.partialmethod.Cell', options)
@@ -1536,170 +1391,122 @@ def test_partialmethod(app):
@pytest.mark.sphinx('html', testroot='ext-autodoc')
-@pytest.mark.filterwarnings('ignore:autodoc_default_flags is now deprecated.')
-def test_merge_autodoc_default_flags1(app):
- app.config.autodoc_default_flags = ['members', 'undoc-members']
- merge_autodoc_default_flags(app, app.config)
- assert app.config.autodoc_default_options == {'members': None,
- 'undoc-members': None}
-
-
-@pytest.mark.sphinx('html', testroot='ext-autodoc')
-@pytest.mark.filterwarnings('ignore:autodoc_default_flags is now deprecated.')
-def test_merge_autodoc_default_flags2(app):
- app.config.autodoc_default_flags = ['members', 'undoc-members']
- app.config.autodoc_default_options = {'members': 'this,that,order',
- 'inherited-members': 'this'}
- merge_autodoc_default_flags(app, app.config)
- assert app.config.autodoc_default_options == {'members': None,
- 'undoc-members': None,
- 'inherited-members': 'this'}
-
+def test_partialmethod_undoc_members(app):
+ expected = [
+ '',
+ '.. py:class:: Cell',
+ ' :module: target.partialmethod',
+ '',
+ ' An example for partialmethod.',
+ ' ',
+ ' refs: https://docs.python.jp/3/library/functools.html#functools.partialmethod',
+ ' ',
+ ' ',
+ ' .. py:method:: Cell.set_alive()',
+ ' :module: target.partialmethod',
+ ' ',
+ ' Make a cell alive.',
+ ' ',
+ ' ',
+ ' .. py:method:: Cell.set_dead()',
+ ' :module: target.partialmethod',
+ ' ',
+ ' ',
+ ' .. py:method:: Cell.set_state(state)',
+ ' :module: target.partialmethod',
+ ' ',
+ ' Update state of cell to *state*.',
+ ' ',
+ ]
-@pytest.mark.sphinx('html', testroot='ext-autodoc')
-def test_autodoc_default_options(app):
- # no settings
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' not in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
- actual = do_autodoc(app, 'class', 'target.CustomIter')
- assert ' .. py:method:: target.CustomIter' not in actual
-
- # with :members:
- app.config.autodoc_default_options = {'members': None}
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
-
- # with :members: = True
- app.config.autodoc_default_options = {'members': True}
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
-
- # with :members: and :undoc-members:
- app.config.autodoc_default_options = {
- 'members': None,
- 'undoc-members': None,
- }
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' in actual
- assert ' .. py:attribute:: EnumCls.val4' in actual
-
- # with :special-members:
- # Note that :members: must be *on* for :special-members: to work.
- app.config.autodoc_default_options = {
- 'members': None,
- 'special-members': None
- }
- actual = do_autodoc(app, 'class', 'target.CustomIter')
- assert ' .. py:method:: CustomIter.__init__()' in actual
- assert ' Create a new `CustomIter`.' in actual
- assert ' .. py:method:: CustomIter.__iter__()' in actual
- assert ' Iterate squares of each value.' in actual
- if not IS_PYPY:
- assert ' .. py:attribute:: CustomIter.__weakref__' in actual
- assert ' list of weak references to the object (if defined)' in actual
-
- # :exclude-members: None - has no effect. Unlike :members:,
- # :special-members:, etc. where None == "include all", here None means
- # "no/false/off".
- app.config.autodoc_default_options = {
- 'members': None,
- 'exclude-members': None,
- }
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
- app.config.autodoc_default_options = {
- 'members': None,
- 'special-members': None,
- 'exclude-members': None,
- }
- actual = do_autodoc(app, 'class', 'target.CustomIter')
- assert ' .. py:method:: CustomIter.__init__()' in actual
- assert ' Create a new `CustomIter`.' in actual
- assert ' .. py:method:: CustomIter.__iter__()' in actual
- assert ' Iterate squares of each value.' in actual
- if not IS_PYPY:
- assert ' .. py:attribute:: CustomIter.__weakref__' in actual
- assert ' list of weak references to the object (if defined)' in actual
- assert ' .. py:method:: CustomIter.snafucate()' in actual
- assert ' Makes this snafucated.' in actual
+ options = {"members": None,
+ "undoc-members": None}
+ actual = do_autodoc(app, 'class', 'target.partialmethod.Cell', options)
+ assert list(actual) == expected
+@pytest.mark.skipif(sys.version_info < (3, 6), reason='py36+ is available since python3.6.')
@pytest.mark.sphinx('html', testroot='ext-autodoc')
-def test_autodoc_default_options_with_values(app):
- # with :members:
- app.config.autodoc_default_options = {'members': 'val1,val2'}
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' in actual
- assert ' .. py:attribute:: EnumCls.val2' in actual
- assert ' .. py:attribute:: EnumCls.val3' not in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
-
- # with :member-order:
- app.config.autodoc_default_options = {
- 'members': None,
- 'member-order': 'bysource',
- }
- actual = do_autodoc(app, 'class', 'target.Class')
- assert list(filter(lambda l: '::' in l, actual)) == [
- '.. py:class:: Class(arg)',
- ' .. py:attribute:: Class.descr',
- ' .. py:method:: Class.meth()',
- ' .. py:method:: Class.skipmeth()',
- ' .. py:method:: Class.excludemeth()',
- ' .. py:attribute:: Class.attr',
- ' .. py:attribute:: Class.prop',
- ' .. py:attribute:: Class.docattr',
- ' .. py:attribute:: Class.udocattr',
- ' .. py:attribute:: Class.mdocattr',
- ' .. py:classmethod:: Class.moore(a, e, f) -> happiness',
- ' .. py:attribute:: Class.inst_attr_inline',
- ' .. py:attribute:: Class.inst_attr_comment',
- ' .. py:attribute:: Class.inst_attr_string',
+def test_autodoc_typed_instance_variables(app):
+ options = {"members": None,
+ "undoc-members": True}
+ actual = do_autodoc(app, 'module', 'target.typed_vars', options)
+ assert list(actual) == [
+ '',
+ '.. py:module:: target.typed_vars',
+ '',
+ '',
+ '.. py:class:: Class()',
+ ' :module: target.typed_vars',
+ '',
+ ' ',
+ ' .. py:attribute:: Class.attr1',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: 0',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Class.attr2',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: None',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Class.attr3',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: 0',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Class.attr4',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: None',
+ ' ',
+ ' attr4',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Class.attr5',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: None',
+ ' ',
+ ' attr5',
+ ' ',
+ ' ',
+ ' .. py:attribute:: Class.attr6',
+ ' :module: target.typed_vars',
+ ' :type: int',
+ ' :value: None',
+ ' ',
+ ' attr6',
+ ' ',
+ '',
+ '.. py:data:: attr1',
+ ' :module: target.typed_vars',
+ ' :type: str',
+ " :value: ''",
+ '',
+ ' attr1',
+ ' ',
+ '',
+ '.. py:data:: attr2',
+ ' :module: target.typed_vars',
+ ' :type: str',
+ ' :value: None',
+ '',
+ ' attr2',
+ ' ',
+ '',
+ '.. py:data:: attr3',
+ ' :module: target.typed_vars',
+ ' :type: str',
+ " :value: ''",
+ '',
+ ' attr3',
+ ' '
]
- # with :special-members:
- app.config.autodoc_default_options = {
- 'special-members': '__init__,__iter__',
- }
- actual = do_autodoc(app, 'class', 'target.CustomIter')
- assert ' .. py:method:: CustomIter.__init__()' in actual
- assert ' Create a new `CustomIter`.' in actual
- assert ' .. py:method:: CustomIter.__iter__()' in actual
- assert ' Iterate squares of each value.' in actual
- if not IS_PYPY:
- assert ' .. py:attribute:: CustomIter.__weakref__' not in actual
- assert ' list of weak references to the object (if defined)' not in actual
-
- # with :exclude-members:
- app.config.autodoc_default_options = {
- 'members': None,
- 'exclude-members': 'val1'
- }
- actual = do_autodoc(app, 'class', 'target.enum.EnumCls')
- assert ' .. py:attribute:: EnumCls.val1' not in actual
- assert ' .. py:attribute:: EnumCls.val2' in actual
- assert ' .. py:attribute:: EnumCls.val3' in actual
- assert ' .. py:attribute:: EnumCls.val4' not in actual
- app.config.autodoc_default_options = {
- 'members': None,
- 'special-members': None,
- 'exclude-members': '__weakref__,snafucate',
- }
- actual = do_autodoc(app, 'class', 'target.CustomIter')
- assert ' .. py:method:: CustomIter.__init__()' in actual
- assert ' Create a new `CustomIter`.' in actual
- assert ' .. py:method:: CustomIter.__iter__()' in actual
- assert ' Iterate squares of each value.' in actual
- if not IS_PYPY:
- assert ' .. py:attribute:: CustomIter.__weakref__' not in actual
- assert ' list of weak references to the object (if defined)' not in actual
- assert ' .. py:method:: CustomIter.snafucate()' not in actual
- assert ' Makes this snafucated.' not in actual
-
@pytest.mark.sphinx('html', testroot='pycode-egg')
def test_autodoc_for_egged_code(app):
@@ -1713,7 +1520,7 @@ def test_autodoc_for_egged_code(app):
'',
'.. py:data:: CONSTANT',
' :module: sample',
- ' :annotation: = 1',
+ ' :value: 1',
'',
' constant on sample.py',
' ',