1""" 2 test_ext_autodoc_autodata 3 ~~~~~~~~~~~~~~~~~~~~~~~~~ 4 5 Test the autodoc extension. This tests mainly the Documenters; the auto 6 directives are tested in a test source file translated by test_build. 7 8 :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. 9 :license: BSD, see LICENSE for details. 10""" 11 12import sys 13 14import pytest 15 16from .test_ext_autodoc import do_autodoc 17 18 19@pytest.mark.sphinx('html', testroot='ext-autodoc') 20def test_autodata(app): 21 actual = do_autodoc(app, 'data', 'target.integer') 22 assert list(actual) == [ 23 '', 24 '.. py:data:: integer', 25 ' :module: target', 26 ' :value: 1', 27 '', 28 ' documentation for the integer', 29 '', 30 ] 31 32 33@pytest.mark.sphinx('html', testroot='ext-autodoc') 34def test_autodata_novalue(app): 35 options = {'no-value': True} 36 actual = do_autodoc(app, 'data', 'target.integer', options) 37 assert list(actual) == [ 38 '', 39 '.. py:data:: integer', 40 ' :module: target', 41 '', 42 ' documentation for the integer', 43 '', 44 ] 45 46 47@pytest.mark.skipif(sys.version_info < (3, 6), reason='python 3.6+ is required.') 48@pytest.mark.sphinx('html', testroot='ext-autodoc') 49def test_autodata_typed_variable(app): 50 actual = do_autodoc(app, 'data', 'target.typed_vars.attr2') 51 assert list(actual) == [ 52 '', 53 '.. py:data:: attr2', 54 ' :module: target.typed_vars', 55 ' :type: str', 56 '', 57 ' attr2', 58 '', 59 ] 60 61 62@pytest.mark.skipif(sys.version_info < (3, 6), reason='python 3.6+ is required.') 63@pytest.mark.sphinx('html', testroot='ext-autodoc') 64def test_autodata_type_comment(app): 65 actual = do_autodoc(app, 'data', 'target.typed_vars.attr3') 66 assert list(actual) == [ 67 '', 68 '.. py:data:: attr3', 69 ' :module: target.typed_vars', 70 ' :type: str', 71 " :value: ''", 72 '', 73 ' attr3', 74 '', 75 ] 76 77 78@pytest.mark.sphinx('html', testroot='ext-autodoc') 79def test_autodata_GenericAlias(app): 80 actual = do_autodoc(app, 'data', 'target.genericalias.T') 81 if sys.version_info < (3, 7): 82 assert list(actual) == [ 83 '', 84 '.. py:data:: T', 85 ' :module: target.genericalias', 86 ' :value: typing.List[int]', 87 '', 88 ' A list of int', 89 '', 90 ] 91 else: 92 assert list(actual) == [ 93 '', 94 '.. py:data:: T', 95 ' :module: target.genericalias', 96 '', 97 ' A list of int', 98 '', 99 ' alias of List[int]', 100 '', 101 ] 102 103 104@pytest.mark.sphinx('html', testroot='ext-autodoc') 105def test_autodata_NewType(app): 106 actual = do_autodoc(app, 'data', 'target.typevar.T6') 107 assert list(actual) == [ 108 '', 109 '.. py:data:: T6', 110 ' :module: target.typevar', 111 '', 112 ' T6', 113 '', 114 ' alias of :class:`int`', 115 '', 116 ] 117 118 119@pytest.mark.sphinx('html', testroot='ext-autodoc') 120def test_autodata_TypeVar(app): 121 actual = do_autodoc(app, 'data', 'target.typevar.T1') 122 assert list(actual) == [ 123 '', 124 '.. py:data:: T1', 125 ' :module: target.typevar', 126 '', 127 ' T1', 128 '', 129 " alias of TypeVar('T1')", 130 '', 131 ] 132 133 134@pytest.mark.skipif(sys.version_info < (3, 6), reason='python 3.6+ is required.') 135@pytest.mark.sphinx('html', testroot='ext-autodoc') 136def test_autodata_hide_value(app): 137 actual = do_autodoc(app, 'data', 'target.hide_value.SENTINEL1') 138 assert list(actual) == [ 139 '', 140 '.. py:data:: SENTINEL1', 141 ' :module: target.hide_value', 142 '', 143 ' docstring', 144 '', 145 ' :meta hide-value:', 146 '', 147 ] 148 149 actual = do_autodoc(app, 'data', 'target.hide_value.SENTINEL2') 150 assert list(actual) == [ 151 '', 152 '.. py:data:: SENTINEL2', 153 ' :module: target.hide_value', 154 '', 155 ' :meta hide-value:', 156 '', 157 ] 158