2019-12-31 23:40:13 -06:00
|
|
|
"""Test the autodoc extension. This tests mainly for private-members option.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
2020-11-20 12:04:26 -06:00
|
|
|
|
2024-03-25 05:03:44 -05:00
|
|
|
from tests.test_extensions.autodoc_util import do_autodoc
|
2019-12-31 23:40:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_private_field(app):
|
|
|
|
app.config.autoclass_content = 'class'
|
|
|
|
options = {"members": None}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
'',
|
2020-04-13 09:55:07 -05:00
|
|
|
'',
|
2020-12-26 10:42:15 -06:00
|
|
|
'.. py:data:: _PUBLIC_CONSTANT',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: None',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
'',
|
2020-04-13 09:55:07 -05:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
' public_function is a docstring().',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
2019-12-31 23:40:13 -06:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_private_field_and_private_members(app):
|
|
|
|
app.config.autoclass_content = 'class'
|
|
|
|
options = {"members": None,
|
|
|
|
"private-members": None}
|
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
'',
|
|
|
|
'',
|
2020-12-26 10:42:15 -06:00
|
|
|
'.. py:data:: PRIVATE_CONSTANT',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: None',
|
|
|
|
'',
|
|
|
|
' :meta private:',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'.. py:data:: _PUBLIC_CONSTANT',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: None',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
'',
|
2020-04-13 09:55:07 -05:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
' public_function is a docstring().',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
'',
|
2019-12-31 23:40:13 -06:00
|
|
|
'.. py:function:: private_function(name)',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
' private_function is a docstring().',
|
2020-03-08 00:31:14 -06:00
|
|
|
'',
|
2019-12-31 23:40:13 -06:00
|
|
|
' :meta private:',
|
2020-03-08 00:31:14 -06:00
|
|
|
'',
|
2019-12-31 23:40:13 -06:00
|
|
|
]
|
2020-08-01 11:26:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_private_members(app):
|
|
|
|
app.config.autoclass_content = 'class'
|
|
|
|
options = {"members": None,
|
2020-12-26 10:42:15 -06:00
|
|
|
"private-members": "_PUBLIC_CONSTANT,_public_function"}
|
2020-08-01 11:26:05 -05:00
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
'',
|
|
|
|
'',
|
2020-12-26 10:42:15 -06:00
|
|
|
'.. py:data:: _PUBLIC_CONSTANT',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: None',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
'',
|
2020-08-01 11:26:05 -05:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
' public_function is a docstring().',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
]
|
2022-05-11 06:19:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_private_attributes(app):
|
|
|
|
app.config.autoclass_content = 'class'
|
|
|
|
options = {"members": None}
|
|
|
|
actual = do_autodoc(app, 'class', 'target.private.Foo', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:class:: Foo()',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:attribute:: Foo._public_attribute',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: 47',
|
|
|
|
'',
|
|
|
|
' A public class attribute whose name starts with an underscore.',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_private_attributes_and_private_members(app):
|
|
|
|
app.config.autoclass_content = 'class'
|
|
|
|
options = {"members": None,
|
|
|
|
"private-members": None}
|
|
|
|
actual = do_autodoc(app, 'class', 'target.private.Foo', options)
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:class:: Foo()',
|
|
|
|
' :module: target.private',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:attribute:: Foo._public_attribute',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: 47',
|
|
|
|
'',
|
|
|
|
' A public class attribute whose name starts with an underscore.',
|
|
|
|
'',
|
|
|
|
' :meta public:',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
' .. py:attribute:: Foo.private_attribute',
|
|
|
|
' :module: target.private',
|
|
|
|
' :value: 11',
|
|
|
|
'',
|
|
|
|
' A private class attribute whose name does not start with an underscore.',
|
|
|
|
'',
|
|
|
|
' :meta private:',
|
|
|
|
'',
|
|
|
|
]
|