2022-02-19 20:57:02 -06:00
|
|
|
"""Test the autodoc extension.
|
2020-12-26 21:04:12 -06:00
|
|
|
|
2022-02-19 20:57:02 -06:00
|
|
|
This tests mainly the Documenters; the auto directives are tested in a test
|
|
|
|
source file translated by test_build.
|
2020-12-26 21:04:12 -06:00
|
|
|
"""
|
|
|
|
|
2020-12-28 06:46:57 -06:00
|
|
|
import sys
|
|
|
|
|
2020-12-26 21:04:12 -06:00
|
|
|
import pytest
|
|
|
|
|
2024-03-25 05:03:44 -05:00
|
|
|
from tests.test_extensions.autodoc_util import do_autodoc
|
2020-12-26 21:04:12 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_empty_all(app):
|
2021-02-01 03:58:09 -06:00
|
|
|
options = {'members': None}
|
2020-12-26 21:04:12 -06:00
|
|
|
actual = do_autodoc(app, 'module', 'target.empty_all', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.empty_all',
|
|
|
|
'',
|
2022-09-13 14:20:02 -05:00
|
|
|
' docsting of empty_all module.',
|
2020-12-26 21:04:12 -06:00
|
|
|
'',
|
|
|
|
]
|
2020-12-29 03:33:36 -06:00
|
|
|
|
|
|
|
|
2021-05-08 01:33:18 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_automodule(app):
|
|
|
|
options = {'members': None}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.module', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.module',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: annotated',
|
|
|
|
' :module: target.module',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: documented',
|
|
|
|
' :module: target.module',
|
|
|
|
' :value: 1',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_automodule_undoc_members(app):
|
|
|
|
options = {'members': None,
|
|
|
|
'undoc-members': None}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.module', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.module',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: annotated',
|
|
|
|
' :module: target.module',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: documented',
|
|
|
|
' :module: target.module',
|
|
|
|
' :value: 1',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: undoc_annotated',
|
|
|
|
' :module: target.module',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_automodule_special_members(app):
|
|
|
|
options = {'members': None,
|
|
|
|
'special-members': None}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.module', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.module',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: __documented_special__',
|
|
|
|
' :module: target.module',
|
|
|
|
' :value: 1',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: annotated',
|
|
|
|
' :module: target.module',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: documented',
|
|
|
|
' :module: target.module',
|
|
|
|
' :value: 1',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-04-02 11:42:16 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_automodule_inherited_members(app):
|
|
|
|
options = {'members': None,
|
|
|
|
'undoc-members': None,
|
|
|
|
'inherited-members': 'Base, list'}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.inheritance', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.inheritance',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:class:: Base()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
'',
|
2022-06-13 12:49:07 -05:00
|
|
|
' .. py:attribute:: Base.inheritedattr',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
' :value: None',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
'',
|
2022-04-02 11:42:16 -05:00
|
|
|
' .. py:method:: Base.inheritedclassmeth()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
' :classmethod:',
|
|
|
|
'',
|
|
|
|
' Inherited class method.',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:method:: Base.inheritedmeth()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
' Inherited function.',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:method:: Base.inheritedstaticmeth(cls)',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
' :staticmethod:',
|
|
|
|
'',
|
|
|
|
' Inherited static method.',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:class:: Derived()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:method:: Derived.inheritedmeth()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
' Inherited function.',
|
|
|
|
'',
|
|
|
|
'',
|
2022-06-16 13:33:55 -05:00
|
|
|
'.. py:class:: MyList(iterable=(), /)',
|
2022-04-02 11:42:16 -05:00
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:method:: MyList.meth()',
|
|
|
|
' :module: target.inheritance',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-12-28 06:46:57 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc',
|
|
|
|
confoverrides={'autodoc_mock_imports': ['missing_module',
|
|
|
|
'missing_package1',
|
|
|
|
'missing_package2',
|
|
|
|
'missing_package3',
|
|
|
|
'sphinx.missing_module4']})
|
|
|
|
@pytest.mark.usefixtures("rollback_sysmodules")
|
|
|
|
def test_subclass_of_mocked_object(app):
|
|
|
|
sys.modules.pop('target', None) # unload target module to clear the module cache
|
|
|
|
|
2021-02-01 03:58:09 -06:00
|
|
|
options = {'members': None}
|
2020-12-28 06:46:57 -06:00
|
|
|
actual = do_autodoc(app, 'module', 'target.need_mocks', options)
|
2022-01-01 04:37:42 -06:00
|
|
|
assert '.. py:class:: Inherited(*args: ~typing.Any, **kwargs: ~typing.Any)' in actual
|