2022-02-19 20:57:02 -06:00
|
|
|
"""Test the autodoc extension.
|
2020-11-14 11:22:45 -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-11-14 11:22:45 -06:00
|
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
2020-11-20 12:04:26 -06:00
|
|
|
|
2024-01-16 20:38:46 -06:00
|
|
|
from tests.test_extensions.test_ext_autodoc import do_autodoc
|
2020-11-14 11:22:45 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.Class.attr')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Class.attr',
|
|
|
|
' :module: target',
|
|
|
|
" :value: 'bar'",
|
|
|
|
'',
|
|
|
|
' should be documented -- süß',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_novalue(app):
|
2022-01-30 10:38:12 -06:00
|
|
|
options = {'no-value': None}
|
2020-11-14 11:22:45 -06:00
|
|
|
actual = do_autodoc(app, 'attribute', 'target.Class.attr', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Class.attr',
|
|
|
|
' :module: target',
|
|
|
|
'',
|
|
|
|
' should be documented -- süß',
|
|
|
|
'',
|
|
|
|
]
|
2020-11-18 09:32:49 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_typed_variable(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.typed_vars.Class.attr2')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Class.attr2',
|
|
|
|
' :module: target.typed_vars',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-12-13 04:49:36 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_typed_variable_in_alias(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.typed_vars.Alias.attr2')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Alias.attr2',
|
|
|
|
' :module: target.typed_vars',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-11-18 09:32:49 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_instance_variable(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.typed_vars.Class.attr4')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Class.attr4',
|
|
|
|
' :module: target.typed_vars',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' attr4',
|
|
|
|
'',
|
|
|
|
]
|
2020-11-21 08:56:16 -06:00
|
|
|
|
|
|
|
|
2020-12-13 04:49:36 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_instance_variable_in_alias(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.typed_vars.Alias.attr4')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Alias.attr4',
|
|
|
|
' :module: target.typed_vars',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' attr4',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-05-29 23:50:07 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_instance_variable_without_comment(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.instance_variable.Bar.attr4')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Bar.attr4',
|
|
|
|
' :module: target.instance_variable',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-11-21 03:22:41 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_slots_variable_list(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.slots.Foo.attr')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Foo.attr',
|
|
|
|
' :module: target.slots',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_slots_variable_dict(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.slots.Bar.attr1')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Bar.attr1',
|
|
|
|
' :module: target.slots',
|
2021-10-23 00:59:36 -05:00
|
|
|
' :type: int',
|
2020-11-21 03:22:41 -06:00
|
|
|
'',
|
|
|
|
' docstring of attr1',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_slots_variable_str(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.slots.Baz.attr')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Baz.attr',
|
|
|
|
' :module: target.slots',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-11-27 22:47:23 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_GenericAlias(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.genericalias.Class.T')
|
2022-06-16 13:33:55 -05:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Class.T',
|
|
|
|
' :module: target.genericalias',
|
|
|
|
'',
|
|
|
|
' A list of int',
|
|
|
|
'',
|
|
|
|
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]',
|
|
|
|
'',
|
|
|
|
]
|
2020-11-27 22:47:23 -06:00
|
|
|
|
|
|
|
|
2020-12-24 23:28:28 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_autoattribute_hide_value(app):
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.hide_value.Foo.SENTINEL1')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Foo.SENTINEL1',
|
|
|
|
' :module: target.hide_value',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
' :meta hide-value:',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'attribute', 'target.hide_value.Foo.SENTINEL2')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:attribute:: Foo.SENTINEL2',
|
|
|
|
' :module: target.hide_value',
|
|
|
|
'',
|
|
|
|
' :meta hide-value:',
|
|
|
|
'',
|
|
|
|
]
|