2024-08-11 14:58:56 +01:00
|
|
|
"""Test the autodoc extension. This tests mainly for private-members option."""
|
2020-01-01 14:40:13 +09:00
|
|
|
|
|
|
|
|
import pytest
|
2020-11-20 19:04:26 +01:00
|
|
|
|
2024-03-25 11:03:44 +01:00
|
|
|
from tests.test_extensions.autodoc_util import do_autodoc
|
2020-01-01 14:40:13 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_private_field(app):
|
|
|
|
|
app.config.autoclass_content = 'class'
|
2024-08-11 14:58:56 +01:00
|
|
|
options = {'members': None}
|
2020-01-01 14:40:13 +09:00
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
|
'',
|
2020-04-13 15:55:07 +01:00
|
|
|
'',
|
2020-12-27 01:42:15 +09:00
|
|
|
'.. py:data:: _PUBLIC_CONSTANT',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
' :value: None',
|
|
|
|
|
'',
|
|
|
|
|
' :meta public:',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
2020-04-13 15:55:07 +01:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
'',
|
|
|
|
|
' public_function is a docstring().',
|
|
|
|
|
'',
|
|
|
|
|
' :meta public:',
|
|
|
|
|
'',
|
2020-01-01 14:40:13 +09:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_private_field_and_private_members(app):
|
|
|
|
|
app.config.autoclass_content = 'class'
|
2024-08-11 14:58:56 +01:00
|
|
|
options = {
|
|
|
|
|
'members': None,
|
|
|
|
|
'private-members': None,
|
|
|
|
|
}
|
2020-01-01 14:40:13 +09:00
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
2020-12-27 01:42:15 +09: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 15:55:07 +01:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
'',
|
|
|
|
|
' public_function is a docstring().',
|
|
|
|
|
'',
|
|
|
|
|
' :meta public:',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
2020-01-01 14:40:13 +09:00
|
|
|
'.. py:function:: private_function(name)',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
'',
|
|
|
|
|
' private_function is a docstring().',
|
2020-03-08 15:31:14 +09:00
|
|
|
'',
|
2020-01-01 14:40:13 +09:00
|
|
|
' :meta private:',
|
2020-03-08 15:31:14 +09:00
|
|
|
'',
|
2020-01-01 14:40:13 +09:00
|
|
|
]
|
2020-08-02 01:26:05 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_private_members(app):
|
|
|
|
|
app.config.autoclass_content = 'class'
|
2024-08-11 14:58:56 +01:00
|
|
|
options = {
|
|
|
|
|
'members': None,
|
|
|
|
|
'private-members': '_PUBLIC_CONSTANT,_public_function',
|
|
|
|
|
}
|
2020-08-02 01:26:05 +09:00
|
|
|
actual = do_autodoc(app, 'module', 'target.private', options)
|
|
|
|
|
assert list(actual) == [
|
|
|
|
|
'',
|
|
|
|
|
'.. py:module:: target.private',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
2020-12-27 01:42:15 +09:00
|
|
|
'.. py:data:: _PUBLIC_CONSTANT',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
' :value: None',
|
|
|
|
|
'',
|
|
|
|
|
' :meta public:',
|
|
|
|
|
'',
|
|
|
|
|
'',
|
2020-08-02 01:26:05 +09:00
|
|
|
'.. py:function:: _public_function(name)',
|
|
|
|
|
' :module: target.private',
|
|
|
|
|
'',
|
|
|
|
|
' public_function is a docstring().',
|
|
|
|
|
'',
|
|
|
|
|
' :meta public:',
|
|
|
|
|
'',
|
|
|
|
|
]
|
2022-05-11 13:19:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
|
def test_private_attributes(app):
|
|
|
|
|
app.config.autoclass_content = 'class'
|
2024-08-11 14:58:56 +01:00
|
|
|
options = {'members': None}
|
2022-05-11 13:19:24 +02:00
|
|
|
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'
|
2024-08-11 14:58:56 +01:00
|
|
|
options = {
|
|
|
|
|
'members': None,
|
|
|
|
|
'private-members': None,
|
|
|
|
|
}
|
2022-05-11 13:19:24 +02:00
|
|
|
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:',
|
|
|
|
|
'',
|
|
|
|
|
]
|