From 336885c4e2282ab93f1dfead7b35a4980ecaff34 Mon Sep 17 00:00:00 2001 From: Anselm Kruis Date: Wed, 11 May 2022 13:19:24 +0200 Subject: [PATCH] Add test cases for #8180 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. --- .../roots/test-ext-autodoc/target/private.py | 12 +++++ tests/test_ext_autodoc_private_members.py | 54 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tests/roots/test-ext-autodoc/target/private.py b/tests/roots/test-ext-autodoc/target/private.py index 02d174863f9..e46344818a7 100644 --- a/tests/roots/test-ext-autodoc/target/private.py +++ b/tests/roots/test-ext-autodoc/target/private.py @@ -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 diff --git a/tests/test_ext_autodoc_private_members.py b/tests/test_ext_autodoc_private_members.py index bdb9478215c..bf707bf51aa 100644 --- a/tests/test_ext_autodoc_private_members.py +++ b/tests/test_ext_autodoc_private_members.py @@ -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:', + '', + ]