mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #7709 from tk0miya/refactor_test_ext_autodoc
refactor: test: Separate tests for autofunction
This commit is contained in:
commit
a1293e2825
@ -1,6 +1,6 @@
|
||||
"""
|
||||
test_autodoc
|
||||
~~~~~~~~~~~~
|
||||
test_ext_autodoc
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Test the autodoc extension. This tests mainly the Documenters; the auto
|
||||
directives are tested in a test source file translated by test_build.
|
||||
@ -837,21 +837,6 @@ def test_autodoc_descriptor(app):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autodoc_c_module(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_autodoc_member_order(app):
|
||||
# case member-order='bysource'
|
||||
@ -1186,96 +1171,6 @@ def test_descriptor_class(app):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autofunction_for_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',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autofunction_for_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_autofunction_for_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_autofunction_for_builtin(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_autofunction_for_methoddescriptor(app):
|
||||
actual = do_autodoc(app, 'function', 'builtins.int.__add__')
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:function:: int.__add__(self, value, /)',
|
||||
' :module: builtins',
|
||||
'',
|
||||
' Return self+value.',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_autofunction_for_decorated(app):
|
||||
actual = do_autodoc(app, 'function', 'target.decorator.foo')
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:function:: foo()',
|
||||
' :module: target.decorator',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_automethod_for_builtin(app):
|
||||
actual = do_autodoc(app, 'method', 'builtins.int.__add__')
|
||||
@ -1495,19 +1390,6 @@ def test_partialmethod(app):
|
||||
assert list(actual) == expected
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_wrappedfunction(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.',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_partialmethod_undoc_members(app):
|
||||
expected = [
|
||||
@ -1688,22 +1570,6 @@ def test_singledispatch(app):
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_singledispatch_autofunction(app):
|
||||
options = {}
|
||||
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:function:: func(arg, kwarg=None)',
|
||||
' func(arg: int, kwarg=None)',
|
||||
' func(arg: str, kwarg=None)',
|
||||
' :module: target.singledispatch',
|
||||
'',
|
||||
' A function for general use.',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.version_info < (3, 8),
|
||||
reason='singledispatchmethod is available since python3.8')
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
|
148
tests/test_ext_autodoc_autofunction.py
Normal file
148
tests/test_ext_autodoc_autofunction.py
Normal file
@ -0,0 +1,148 @@
|
||||
"""
|
||||
test_ext_autodoc_autofunction
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Test the autodoc extension. This tests mainly the Documenters; the auto
|
||||
directives are tested in a test source file translated by test_build.
|
||||
|
||||
:copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from test_ext_autodoc import do_autodoc
|
||||
|
||||
|
||||
@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',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@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) == [
|
||||
'',
|
||||
'.. py:function:: int.__add__(self, value, /)',
|
||||
' :module: builtins',
|
||||
'',
|
||||
' 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) == [
|
||||
'',
|
||||
'.. py:function:: foo()',
|
||||
' :module: target.decorator',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||
def test_singledispatch(app):
|
||||
options = {}
|
||||
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
|
||||
assert list(actual) == [
|
||||
'',
|
||||
'.. py:function:: func(arg, kwarg=None)',
|
||||
' func(arg: int, kwarg=None)',
|
||||
' func(arg: str, kwarg=None)',
|
||||
' :module: target.singledispatch',
|
||||
'',
|
||||
' A function for general use.',
|
||||
'',
|
||||
]
|
||||
|
||||
|
||||
@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.',
|
||||
'',
|
||||
]
|
Loading…
Reference in New Issue
Block a user