2020-05-22 09:41:45 -05:00
|
|
|
"""
|
|
|
|
Test the autodoc extension. This tests mainly the Documenters; the auto
|
|
|
|
directives are tested in a test source file translated by test_build.
|
|
|
|
|
2022-01-01 03:45:03 -06:00
|
|
|
:copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
|
2020-05-22 09:41:45 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
2020-11-20 12:04:26 -06:00
|
|
|
|
|
|
|
from .test_ext_autodoc import do_autodoc
|
2020-05-22 09:41:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_classes(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.classes.Foo')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: Foo()',
|
|
|
|
' :module: target.classes',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.classes.Bar')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: Bar(x, y)',
|
|
|
|
' :module: target.classes',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
actual = do_autodoc(app, 'function', 'target.classes.Baz')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: Baz(x, y)',
|
|
|
|
' :module: target.classes',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
2020-11-01 03:23:24 -06:00
|
|
|
actual = do_autodoc(app, 'function', 'target.classes.Qux')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: Qux(foo, bar)',
|
|
|
|
' :module: target.classes',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
2020-05-22 09:41:45 -05:00
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_callable(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.callable.function')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: function(arg1, arg2, **kwargs)',
|
|
|
|
' :module: target.callable',
|
|
|
|
'',
|
|
|
|
' A callable object that behaves like a function.',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_method(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.callable.method')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: method(arg1, arg2)',
|
|
|
|
' :module: target.callable',
|
|
|
|
'',
|
|
|
|
' docstring of Callable.method().',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_builtin_function(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'os.umask')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: umask(mask, /)',
|
|
|
|
' :module: os',
|
|
|
|
'',
|
|
|
|
' Set the current numeric umask and return the previous umask.',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_methoddescriptor(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'builtins.int.__add__')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
2020-06-27 08:05:02 -05:00
|
|
|
'.. py:function:: __add__(self, value, /)',
|
|
|
|
' :module: builtins.int',
|
2020-05-22 09:41:45 -05:00
|
|
|
'',
|
|
|
|
' Return self+value.',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_decorated(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.decorator.foo')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
2020-07-04 13:08:27 -05:00
|
|
|
'.. py:function:: foo(name=None, age=None)',
|
2020-05-22 09:41:45 -05:00
|
|
|
' :module: target.decorator',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_singledispatch(app):
|
|
|
|
options = {}
|
|
|
|
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
|
2020-11-05 10:36:04 -06:00
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: func(arg, kwarg=None)',
|
2021-05-02 07:00:26 -05:00
|
|
|
' func(arg: float, kwarg=None)',
|
2020-11-05 10:36:04 -06:00
|
|
|
' func(arg: int, kwarg=None)',
|
|
|
|
' func(arg: str, kwarg=None)',
|
|
|
|
' :module: target.singledispatch',
|
|
|
|
'',
|
|
|
|
' A function for general use.',
|
|
|
|
'',
|
|
|
|
]
|
2020-05-22 09:41:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_cfunction(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'time.asctime')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: asctime([tuple]) -> string',
|
|
|
|
' :module: time',
|
|
|
|
'',
|
|
|
|
" Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.",
|
|
|
|
' When the time tuple is not present, current time as returned by localtime()',
|
|
|
|
' is used.',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_wrapped_function(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.wrappedfunction.slow_function')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: slow_function(message, timeout)',
|
|
|
|
' :module: target.wrappedfunction',
|
|
|
|
'',
|
|
|
|
' This function is slow.',
|
|
|
|
'',
|
|
|
|
]
|
2020-06-13 11:19:21 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_wrapped_function_contextmanager(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.wrappedfunction.feeling_good')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
2021-12-23 19:50:04 -06:00
|
|
|
'.. py:function:: feeling_good(x: int, y: int) -> typing.Generator',
|
2020-06-13 11:19:21 -05:00
|
|
|
' :module: target.wrappedfunction',
|
|
|
|
'',
|
|
|
|
" You'll feel better in this context!",
|
|
|
|
'',
|
|
|
|
]
|
2021-09-16 12:19:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_coroutine(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.functions.coroutinefunc')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: coroutinefunc()',
|
|
|
|
' :module: target.functions',
|
|
|
|
' :async:',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_synchronized_coroutine(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.coroutine.sync_func')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: sync_func()',
|
|
|
|
' :module: target.coroutine',
|
|
|
|
'',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
|
|
|
def test_async_generator(app):
|
|
|
|
actual = do_autodoc(app, 'function', 'target.functions.asyncgenerator')
|
|
|
|
assert list(actual) == [
|
|
|
|
'',
|
|
|
|
'.. py:function:: asyncgenerator()',
|
|
|
|
' :module: target.functions',
|
|
|
|
' :async:',
|
|
|
|
'',
|
|
|
|
]
|