From 42caa497f5b69f1d5d2a013c5dbc3446a4741269 Mon Sep 17 00:00:00 2001 From: Antoine DECHAUME <> Date: Mon, 15 Nov 2021 17:20:33 +0100 Subject: [PATCH] Add a test cases without a documented method --- .../test-ext-autodoc/target/typehints.py | 14 ++++ tests/test_ext_autodoc_configs.py | 75 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/tests/roots/test-ext-autodoc/target/typehints.py b/tests/roots/test-ext-autodoc/target/typehints.py index 29d763eca21..fcdc70b6550 100644 --- a/tests/roots/test-ext-autodoc/target/typehints.py +++ b/tests/roots/test-ext-autodoc/target/typehints.py @@ -92,6 +92,13 @@ def __init__(self, x: int, args: int, kwargs: int) -> None: """ +class _ClassWithoutDocumentedInit: + """Class docstring.""" + + def __init__(self, x: int, args: int, kwargs: int) -> None: + pass + + class _ClassWithDocumentedInitAndStarArgs: """Class docstring.""" @@ -102,3 +109,10 @@ def __init__(self, x: int, *args: int, **kwargs: int) -> None: :param *args: Some integer :param **kwargs: Some integer """ + + +class _ClassWithDocumentedoutInitAndStarArgs: + """Class docstring.""" + + def __init__(self, x: int, *args: int, **kwargs: int) -> None: + pass diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py index 66b75b6f128..48e1ceaf0ed 100644 --- a/tests/test_ext_autodoc_configs.py +++ b/tests/test_ext_autodoc_configs.py @@ -878,6 +878,43 @@ def test_autodoc_typehints_description_no_undoc(app): in context) +@pytest.mark.sphinx('text', testroot='ext-autodoc', + confoverrides={'autodoc_typehints': "description"}) +def test_autodoc_typehints_description_without_documented_init(app): + (app.srcdir / 'index.rst').write_text( + '.. autoclass:: target.typehints._ClassWithDocumentedoutInitAndStarArgs\n' + ' :special-members: __init__\n' + ) + app.build() + context = (app.outdir / 'index.txt').read_text() + assert ('class target.typehints._ClassWithDocumentedoutInitAndStarArgs(x, *args, **kwargs)\n' + '\n' + ' Class docstring.\n' + '\n' + ' Parameters:\n' + ' * **x** (*int*) --\n' + '\n' + ' * ***args** (*int*) --\n' + '\n' + ' * ****kwargs** (*int*) --\n' + '\n' + ' Return type:\n' + ' None\n' + '\n' + ' __init__(x, *args, **kwargs)\n' + '\n' + ' Parameters:\n' + ' * **x** (*int*) --\n' + '\n' + ' * ***args** (*int*) --\n' + '\n' + ' * ****kwargs** (*int*) --\n' + '\n' + ' Return type:\n' + ' None\n' == context) + + + @pytest.mark.sphinx('text', testroot='ext-autodoc', confoverrides={'autodoc_typehints': "description"}) def test_autodoc_typehints_description_with_documented_init(app): @@ -947,6 +984,44 @@ def test_autodoc_typehints_description_with_documented_init_no_undoc(app): == context) +@pytest.mark.sphinx('text', testroot='ext-autodoc', + confoverrides={'autodoc_typehints': "description"}) +def test_autodoc_typehints_description_without_documented_init_no_undoc(app): + (app.srcdir / 'index.rst').write_text( + '.. autoclass:: target.typehints._ClassWithoutDocumentedInit\n' + ' :special-members: __init__\n' + ) + app.build() + context = (app.outdir / 'index.txt').read_text() + assert ('class target.typehints._ClassWithoutDocumentedInit(x, args, kwargs)\n' + '\n' + ' Class docstring.\n' + '\n' + ' Parameters:\n' + ' * **x** (*int*) --\n' + '\n' + ' * **args** (*int*) --\n' + '\n' + ' * **kwargs** (*int*) --\n' + '\n' + ' Return type:\n' + ' None\n' + + '\n' + ' __init__(x, args, kwargs)\n' + '\n' + ' Parameters:\n' + ' * **x** (*int*) --\n' + '\n' + ' * **args** (*int*) --\n' + '\n' + ' * **kwargs** (*int*) --\n' + '\n' + ' Return type:\n' + ' None\n' + == context) + + @pytest.mark.sphinx('text', testroot='ext-autodoc', confoverrides={'autodoc_typehints': "description"}) def test_autodoc_typehints_description_for_invalid_node(app):