mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
test: Add do_autodoc() helper
This commit is contained in:
parent
2f5a66d647
commit
7dad01d18f
@ -18,14 +18,24 @@ from docutils.statemachine import ViewList
|
|||||||
from six import PY3
|
from six import PY3
|
||||||
|
|
||||||
from sphinx.ext.autodoc import (
|
from sphinx.ext.autodoc import (
|
||||||
AutoDirective, ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL
|
AutoDirective, ModuleLevelDocumenter, FunctionDocumenter, cut_lines, between, ALL, Options
|
||||||
)
|
)
|
||||||
|
from sphinx.ext.autodoc.directive import DocumenterBridge
|
||||||
from sphinx.testing.util import SphinxTestApp, Struct # NOQA
|
from sphinx.testing.util import SphinxTestApp, Struct # NOQA
|
||||||
from sphinx.util import logging
|
from sphinx.util import logging
|
||||||
|
from sphinx.util.docutils import LoggingReporter
|
||||||
|
|
||||||
app = None
|
app = None
|
||||||
|
|
||||||
|
|
||||||
|
def do_autodoc(app, objtype, name, options={}):
|
||||||
|
bridge = DocumenterBridge(app.env, LoggingReporter(''), Options(options), 1)
|
||||||
|
documenter = app.registry.documenters[objtype](bridge, name)
|
||||||
|
documenter.generate()
|
||||||
|
|
||||||
|
return bridge.result
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='module', autouse=True)
|
@pytest.fixture(scope='module', autouse=True)
|
||||||
def setup_module(rootdir, sphinx_test_tempdir):
|
def setup_module(rootdir, sphinx_test_tempdir):
|
||||||
try:
|
try:
|
||||||
@ -917,17 +927,8 @@ def test_generate():
|
|||||||
|
|
||||||
@pytest.mark.skipif(sys.version_info < (3, 4),
|
@pytest.mark.skipif(sys.version_info < (3, 4),
|
||||||
reason='functools.partialmethod is available on py34 or above')
|
reason='functools.partialmethod is available on py34 or above')
|
||||||
@pytest.mark.usefixtures('setup_test')
|
@pytest.mark.sphinx('html', testroot='ext-autodoc')
|
||||||
def test_partialmethod():
|
def test_partialmethod(app):
|
||||||
def call_autodoc(objtype, name):
|
|
||||||
inst = app.registry.documenters[objtype](directive, name)
|
|
||||||
inst.generate()
|
|
||||||
result = list(directive.result)
|
|
||||||
del directive.result[:]
|
|
||||||
return result
|
|
||||||
|
|
||||||
options.inherited_members = True
|
|
||||||
options.undoc_members = True
|
|
||||||
expected = [
|
expected = [
|
||||||
'',
|
'',
|
||||||
'.. py:class:: Cell',
|
'.. py:class:: Cell',
|
||||||
@ -962,4 +963,6 @@ def test_partialmethod():
|
|||||||
# TODO: this condition should be updated after 3.7-final release.
|
# TODO: this condition should be updated after 3.7-final release.
|
||||||
expected = '\n'.join(expected).replace(' -> None', '').split('\n')
|
expected = '\n'.join(expected).replace(' -> None', '').split('\n')
|
||||||
|
|
||||||
assert call_autodoc('class', 'target.partialmethod.Cell') == expected
|
options = {"members": ALL}
|
||||||
|
actual = do_autodoc(app, 'class', 'target.partialmethod.Cell', options)
|
||||||
|
assert list(actual) == expected
|
||||||
|
Loading…
Reference in New Issue
Block a user