2022-02-20 02:57:02 +00: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-11 02:01:17 +09:00
|
|
|
"""
|
|
|
|
|
|
2024-11-22 21:54:26 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2021-03-11 02:01:17 +09:00
|
|
|
import pytest
|
|
|
|
|
|
2024-03-25 11:03:44 +01:00
|
|
|
from tests.test_extensions.autodoc_util import do_autodoc
|
2021-03-11 02:01:17 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_properties(app):
|
2021-07-17 15:02:23 +09:00
|
|
|
actual = do_autodoc(app, 'property', 'target.properties.Foo.prop1')
|
2021-03-11 02:01:17 +09:00
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
2021-07-17 15:02:23 +09:00
|
|
|
'.. py:property:: Foo.prop1',
|
2021-03-11 02:01:17 +09:00
|
|
|
' :module: target.properties',
|
|
|
|
|
' :type: int',
|
|
|
|
|
'',
|
|
|
|
|
' docstring',
|
|
|
|
|
'',
|
|
|
|
|
]
|
2021-07-17 15:02:23 +09: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 23:25:02 +09:00
|
|
|
|
|
|
|
|
|
2023-04-06 23:56:17 +02:00
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_properties_with_type_comment(app):
|
2024-08-11 14:58:56 +01:00
|
|
|
actual = do_autodoc(
|
|
|
|
|
app, 'property', 'target.properties.Foo.prop1_with_type_comment'
|
|
|
|
|
)
|
2023-04-06 23:56:17 +02: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 14:58:56 +01:00
|
|
|
actual = do_autodoc(
|
|
|
|
|
app, 'property', 'target.properties.Foo.prop2_with_type_comment'
|
|
|
|
|
)
|
2023-04-06 23:56:17 +02:00
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
|
|
|
|
'.. py:property:: Foo.prop2_with_type_comment',
|
|
|
|
|
' :module: target.properties',
|
|
|
|
|
' :classmethod:',
|
|
|
|
|
' :type: int',
|
|
|
|
|
'',
|
|
|
|
|
' docstring',
|
|
|
|
|
'',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2021-07-22 23:25:02 +09: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 23:56:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_cached_properties_with_type_comment(app):
|
2024-08-11 14:58:56 +01:00
|
|
|
actual = do_autodoc(
|
|
|
|
|
app, 'property', 'target.cached_property.Foo.prop_with_type_comment'
|
|
|
|
|
)
|
2023-04-06 23:56:17 +02:00
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
|
|
|
|
'.. py:property:: Foo.prop_with_type_comment',
|
|
|
|
|
' :module: target.cached_property',
|
|
|
|
|
' :type: int',
|
|
|
|
|
'',
|
|
|
|
|
]
|