2022-02-19 20:57:02 -06:00
|
|
|
"""Test the autodoc extension.
|
|
|
|
|
|
|
|
This tests mainly the Documenters; the auto directives are tested in a test
|
|
|
|
source file translated by test_build.
|
2021-03-10 11:01:17 -06:00
|
|
|
"""
|
|
|
|
|
2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-03-10 11:01:17 -06:00
|
|
|
import pytest
|
|
|
|
|
2024-03-25 05:03:44 -05:00
|
|
|
from tests.test_extensions.autodoc_util import do_autodoc
|
2021-03-10 11:01:17 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_properties(app):
|
2021-07-17 01:02:23 -05:00
|
|
|
actual = do_autodoc(app, 'property', 'target.properties.Foo.prop1')
|
2021-03-10 11:01:17 -06:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
2021-07-17 01:02:23 -05:00
|
|
|
'.. py:property:: Foo.prop1',
|
2021-03-10 11:01:17 -06:00
|
|
|
' :module: target.properties',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
2021-07-17 01:02:23 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_class_properties(app):
|
|
|
|
actual = do_autodoc(app, 'property', 'target.properties.Foo.prop2')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:property:: Foo.prop2',
|
|
|
|
' :module: target.properties',
|
|
|
|
' :classmethod:',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
2021-07-22 09:25:02 -05:00
|
|
|
|
|
|
|
|
2023-04-06 16:56:17 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_properties_with_type_comment(app):
|
2024-08-11 08:58:56 -05:00
|
|
|
actual = do_autodoc(
|
|
|
|
app, 'property', 'target.properties.Foo.prop1_with_type_comment'
|
|
|
|
)
|
2023-04-06 16:56:17 -05:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:property:: Foo.prop1_with_type_comment',
|
|
|
|
' :module: target.properties',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_class_properties_with_type_comment(app):
|
2024-08-11 08:58:56 -05:00
|
|
|
actual = do_autodoc(
|
|
|
|
app, 'property', 'target.properties.Foo.prop2_with_type_comment'
|
|
|
|
)
|
2023-04-06 16:56:17 -05:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:property:: Foo.prop2_with_type_comment',
|
|
|
|
' :module: target.properties',
|
|
|
|
' :classmethod:',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
' docstring',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-07-22 09:25:02 -05:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_cached_properties(app):
|
|
|
|
actual = do_autodoc(app, 'property', 'target.cached_property.Foo.prop')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:property:: Foo.prop',
|
|
|
|
' :module: target.cached_property',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
]
|
2023-04-06 16:56:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_cached_properties_with_type_comment(app):
|
2024-08-11 08:58:56 -05:00
|
|
|
actual = do_autodoc(
|
|
|
|
app, 'property', 'target.cached_property.Foo.prop_with_type_comment'
|
|
|
|
)
|
2023-04-06 16:56:17 -05:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:property:: Foo.prop_with_type_comment',
|
|
|
|
' :module: target.cached_property',
|
|
|
|
' :type: int',
|
|
|
|
'',
|
|
|
|
]
|