Skip to content

Commit

Permalink
Add test cases for sphinx-doc#8180
Browse files Browse the repository at this point in the history
The test checks, if ":meta private:" and ":meta public:" have an effect
in attributes of a class. Currently the new test cases fail.
The fix is in the next commit.
  • Loading branch information
Anselm Kruis committed May 13, 2022
1 parent 1222bed commit e6f2410
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/roots/test-ext-autodoc/target/private.py
Expand Up @@ -13,3 +13,15 @@ def _public_function(name):

PRIVATE_CONSTANT = None #: :meta private:
_PUBLIC_CONSTANT = None #: :meta public:


class Foo:
#: A public class attribute whose name starts with an underscore.
#:
#: :meta public:
_public_attribute = 47

#: A private class attribute whose name does not start with an underscore.
#:
#: :meta private:
private_attribute = 11
54 changes: 54 additions & 0 deletions tests/test_ext_autodoc_private_members.py
Expand Up @@ -102,3 +102,57 @@ def test_private_members(app):
' :meta public:',
'',
]


@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:',
'',
]

0 comments on commit e6f2410

Please sign in to comment.