From 446bee8c661a93a7489d547a4c0473fcbf3f2c42 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 18 Feb 2019 21:53:18 +0900 Subject: [PATCH] refactor: test_autodoc --- tests/test_autodoc.py | 71 +++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 42a1f4f3e..27412a9da 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -9,7 +9,6 @@ :license: BSD, see LICENSE for details. """ -import re import platform import sys from warnings import catch_warnings @@ -517,13 +516,11 @@ def test_docstring_processing(): app.disconnect(lid) -@pytest.mark.usefixtures('setup_test') -def test_new_documenter(): - logging.setup(app, app._status, app._warning) - +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_new_documenter(app): class MyDocumenter(ModuleLevelDocumenter): objtype = 'integer' - directivetype = 'data' + directivetype = 'integer' priority = 100 @classmethod @@ -535,17 +532,19 @@ def test_new_documenter(): app.add_autodocumenter(MyDocumenter) - def assert_result_contains(item, objtype, name, **kw): - app._warning.truncate(0) - inst = app.registry.documenters[objtype](directive, name) - inst.generate(**kw) - # print '\n'.join(directive.result) - assert app._warning.getvalue() == '' - assert item in directive.result - del directive.result[:] - - options.members = ['integer'] - assert_result_contains('.. py:data:: integer', 'module', 'target') + options = {"members": 'integer'} + actual = do_autodoc(app, 'module', 'target', options) + assert list(actual) == [ + '', + '.. py:module:: target', + '', + '', + '.. py:integer:: integer', + ' :module: target', + '', + ' documentation for the integer', + ' ' + ] @pytest.mark.usefixtures('setup_test') @@ -583,23 +582,29 @@ def test_attrgetter_using(): assert_getter_works('class', 'target.Class', Class, ['meth', 'inheritedmeth']) -@pytest.mark.usefixtures('setup_test') -def test_generate(): - def assert_result_contains(item, objtype, name, **kw): - inst = app.registry.documenters[objtype](directive, name) - inst.generate(**kw) - assert item in directive.result - del directive.result[:] +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_py_module(app, warning): + # without py:module + actual = do_autodoc(app, 'method', 'Class.meth') + assert list(actual) == [] + assert ("don't know which module to import for autodocumenting 'Class.meth'" + in warning.getvalue()) - # test auto and given content mixing - directive.env.ref_context['py:module'] = 'target' - assert_result_contains(' Function.', 'method', 'Class.meth') - add_content = ViewList() - add_content.append('Content.', '', 0) - assert_result_contains(' Function.', 'method', - 'Class.meth', more_content=add_content) - assert_result_contains(' Content.', 'method', - 'Class.meth', more_content=add_content) + # with py:module + app.env.ref_context['py:module'] = 'target' + warning.truncate(0) + + actual = do_autodoc(app, 'method', 'Class.meth') + assert list(actual) == [ + '', + '.. py:method:: Class.meth()', + ' :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')