Merge pull request #6109 from tk0miya/refactor_test_autodoc

refactor: test_autodoc
This commit is contained in:
Takeshi KOMIYA 2019-02-27 21:43:14 +09:00 committed by GitHub
commit 6508e8ea5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,7 +9,6 @@
:license: BSD, see LICENSE for details. :license: BSD, see LICENSE for details.
""" """
import re
import platform import platform
import sys import sys
from warnings import catch_warnings from warnings import catch_warnings
@ -517,13 +516,11 @@ def test_docstring_processing():
app.disconnect(lid) app.disconnect(lid)
@pytest.mark.usefixtures('setup_test') @pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_new_documenter(): def test_new_documenter(app):
logging.setup(app, app._status, app._warning)
class MyDocumenter(ModuleLevelDocumenter): class MyDocumenter(ModuleLevelDocumenter):
objtype = 'integer' objtype = 'integer'
directivetype = 'data' directivetype = 'integer'
priority = 100 priority = 100
@classmethod @classmethod
@ -535,17 +532,19 @@ def test_new_documenter():
app.add_autodocumenter(MyDocumenter) app.add_autodocumenter(MyDocumenter)
def assert_result_contains(item, objtype, name, **kw): options = {"members": 'integer'}
app._warning.truncate(0) actual = do_autodoc(app, 'module', 'target', options)
inst = app.registry.documenters[objtype](directive, name) assert list(actual) == [
inst.generate(**kw) '',
# print '\n'.join(directive.result) '.. py:module:: target',
assert app._warning.getvalue() == '' '',
assert item in directive.result '',
del directive.result[:] '.. py:integer:: integer',
' :module: target',
options.members = ['integer'] '',
assert_result_contains('.. py:data:: integer', 'module', 'target') ' documentation for the integer',
' '
]
@pytest.mark.usefixtures('setup_test') @pytest.mark.usefixtures('setup_test')
@ -583,23 +582,29 @@ def test_attrgetter_using():
assert_getter_works('class', 'target.Class', Class, ['meth', 'inheritedmeth']) assert_getter_works('class', 'target.Class', Class, ['meth', 'inheritedmeth'])
@pytest.mark.usefixtures('setup_test') @pytest.mark.sphinx('html', testroot='ext-autodoc')
def test_generate(): def test_py_module(app, warning):
def assert_result_contains(item, objtype, name, **kw): # without py:module
inst = app.registry.documenters[objtype](directive, name) actual = do_autodoc(app, 'method', 'Class.meth')
inst.generate(**kw) assert list(actual) == []
assert item in directive.result assert ("don't know which module to import for autodocumenting 'Class.meth'"
del directive.result[:] in warning.getvalue())
# test auto and given content mixing # with py:module
directive.env.ref_context['py:module'] = 'target' app.env.ref_context['py:module'] = 'target'
assert_result_contains(' Function.', 'method', 'Class.meth') warning.truncate(0)
add_content = ViewList()
add_content.append('Content.', '', 0) actual = do_autodoc(app, 'method', 'Class.meth')
assert_result_contains(' Function.', 'method', assert list(actual) == [
'Class.meth', more_content=add_content) '',
assert_result_contains(' Content.', 'method', '.. py:method:: Class.meth()',
'Class.meth', more_content=add_content) ' :module: target',
'',
' Function.',
' '
]
assert ("don't know which module to import for autodocumenting 'Class.meth'"
not in warning.getvalue())
@pytest.mark.sphinx('html', testroot='ext-autodoc') @pytest.mark.sphinx('html', testroot='ext-autodoc')