Skip to content

Commit

Permalink
Add a test cases without a documented method
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine DECHAUME committed Nov 15, 2021
1 parent 31db588 commit 42caa49
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/roots/test-ext-autodoc/target/typehints.py
Expand Up @@ -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."""

Expand All @@ -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
75 changes: 75 additions & 0 deletions tests/test_ext_autodoc_configs.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 42caa49

Please sign in to comment.