| 1 |
"""Test the autodoc extension. |
| 2 |
|
| 3 |
This tests mainly the Documenters; the auto directives are tested in a test |
| 4 |
source file translated by test_build. |
| 5 |
""" |
| 6 |
|
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
import pytest |
| 10 |
|
| 11 |
from tests.test_ext_autodoc.autodoc_util import do_autodoc |
| 12 |
|
| 13 |
pytestmark = pytest.mark.usefixtures('inject_autodoc_root_into_sys_path') |
| 14 |
|
| 15 |
|
| 16 |
def test_autodata() -> None: |
| 17 |
actual = do_autodoc('data', 'target.integer') |
| 18 |
assert actual == [ |
| 19 |
'', |
| 20 |
'.. py:data:: integer', |
| 21 |
' :module: target', |
| 22 |
' :value: 1', |
| 23 |
'', |
| 24 |
' documentation for the integer', |
| 25 |
'', |
| 26 |
] |
| 27 |
|
| 28 |
|
| 29 |
def test_autodata_novalue() -> None: |
| 30 |
options = {'no-value': None} |
| 31 |
actual = do_autodoc('data', 'target.integer', options=options) |
| 32 |
assert actual == [ |
| 33 |
'', |
| 34 |
'.. py:data:: integer', |
| 35 |
' :module: target', |
| 36 |
'', |
| 37 |
' documentation for the integer', |
| 38 |
'', |
| 39 |
] |
| 40 |
|
| 41 |
|
| 42 |
def test_autodata_typed_variable() -> None: |
| 43 |
actual = do_autodoc('data', 'target.typed_vars.attr2') |
| 44 |
assert actual == [ |
| 45 |
'', |
| 46 |
'.. py:data:: attr2', |
| 47 |
' :module: target.typed_vars', |
| 48 |
' :type: str', |
| 49 |
'', |
| 50 |
' attr2', |
| 51 |
'', |
| 52 |
] |
| 53 |
|
| 54 |
|
| 55 |
def test_autodata_type_comment() -> None: |
| 56 |
actual = do_autodoc('data', 'target.typed_vars.attr3') |
| 57 |
assert actual == [ |
| 58 |
'', |
| 59 |
'.. py:data:: attr3', |
| 60 |
' :module: target.typed_vars', |
| 61 |
' :type: str', |
| 62 |
" :value: ''", |
| 63 |
'', |
| 64 |
' attr3', |
| 65 |
'', |
| 66 |
] |
| 67 |
|
| 68 |
|
| 69 |
def test_autodata_GenericAlias() -> None: |
| 70 |
actual = do_autodoc('data', 'target.genericalias.T') |
| 71 |
assert actual == [ |
| 72 |
'', |
| 73 |
'.. py:data:: T', |
| 74 |
' :module: target.genericalias', |
| 75 |
'', |
| 76 |
' A list of int', |
| 77 |
'', |
| 78 |
' alias of :py:class:`~typing.List`\\ [:py:class:`int`]', |
| 79 |
'', |
| 80 |
] |
| 81 |
|
| 82 |
|
| 83 |
def test_autodata_hide_value() -> None: |
| 84 |
actual = do_autodoc('data', 'target.hide_value.SENTINEL1') |
| 85 |
assert actual == [ |
| 86 |
'', |
| 87 |
'.. py:data:: SENTINEL1', |
| 88 |
' :module: target.hide_value', |
| 89 |
'', |
| 90 |
' docstring', |
| 91 |
'', |
| 92 |
' :meta hide-value:', |
| 93 |
'', |
| 94 |
] |
| 95 |
|
| 96 |
actual = do_autodoc('data', 'target.hide_value.SENTINEL2') |
| 97 |
assert actual == [ |
| 98 |
'', |
| 99 |
'.. py:data:: SENTINEL2', |
| 100 |
' :module: target.hide_value', |
| 101 |
'', |
| 102 |
' :meta hide-value:', |
| 103 |
'', |
| 104 |
] |