From ea0328664787384d561ce276043c89ab2167f0f9 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 17 Oct 2018 01:55:50 +0900 Subject: [PATCH] test: Move autodoc_missing_imports to test-ext-autodoc --- .../target/need_mocks.py} | 0 tests/roots/test-root/autodoc.txt | 2 -- tests/roots/test-root/conf.py | 8 ----- tests/test_autodoc.py | 31 ++++++++++++++----- tests/test_build_texinfo.py | 6 ++-- 5 files changed, 27 insertions(+), 20 deletions(-) rename tests/roots/{test-root/autodoc_missing_imports.py => test-ext-autodoc/target/need_mocks.py} (100%) diff --git a/tests/roots/test-root/autodoc_missing_imports.py b/tests/roots/test-ext-autodoc/target/need_mocks.py similarity index 100% rename from tests/roots/test-root/autodoc_missing_imports.py rename to tests/roots/test-ext-autodoc/target/need_mocks.py diff --git a/tests/roots/test-root/autodoc.txt b/tests/roots/test-root/autodoc.txt index 3c83ebf6e..39d9dd5a7 100644 --- a/tests/roots/test-root/autodoc.txt +++ b/tests/roots/test-root/autodoc.txt @@ -45,5 +45,3 @@ Just testing a few autodoc possibilities... :members: ca1, ia1 Specific members (2 total) - -.. automodule:: autodoc_missing_imports diff --git a/tests/roots/test-root/conf.py b/tests/roots/test-root/conf.py index 42b8295a2..634bd66d3 100644 --- a/tests/roots/test-root/conf.py +++ b/tests/roots/test-root/conf.py @@ -69,14 +69,6 @@ coverage_c_regexes = {'function': r'^PyAPI_FUNC\(.*\)\s+([^_][\w_]+)'} extlinks = {'issue': ('http://bugs.python.org/issue%s', 'issue '), 'pyurl': ('http://python.org/%s', None)} -autodoc_mock_imports = [ - 'missing_module', - 'missing_package1', - 'missing_package2', - 'missing_package3', - 'sphinx.missing_module4', -] - # modify tags from conf.py tags.add('confpytag') # NOQA diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index 5153ce3e3..6e1b988b4 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -35,6 +35,7 @@ IS_PYPY = platform.python_implementation() == 'PyPy' def do_autodoc(app, objtype, name, options=None): if options is None: options = {} + app.env.temp_data.setdefault('docname', 'index') # set dummy docname doccls = app.registry.documenters[objtype] docoptions = process_documenter_options(doccls, app.config, options) bridge = DocumenterBridge(app.env, LoggingReporter(''), docoptions, 1) @@ -1348,33 +1349,49 @@ def test_autofunction_for_callable(app): ] -@pytest.mark.sphinx('html', testroot='root') -def test_mocked_module_imports(app): +@pytest.mark.sphinx('html', testroot='ext-autodoc') +def test_mocked_module_imports(app, warning): + # no autodoc_mock_imports options = {"members": 'TestAutodoc,decoratedFunction'} - actual = do_autodoc(app, 'module', 'autodoc_missing_imports', options) + actual = do_autodoc(app, 'module', 'target.need_mocks', options) + assert list(actual) == [] + assert "autodoc: failed to import module 'need_mocks'" in warning.getvalue() + + # with autodoc_mock_imports + app.config.autodoc_mock_imports = [ + 'missing_module', + 'missing_package1', + 'missing_package2', + 'missing_package3', + 'sphinx.missing_module4', + ] + + warning.truncate(0) + actual = do_autodoc(app, 'module', 'target.need_mocks', options) assert list(actual) == [ '', - '.. py:module:: autodoc_missing_imports', + '.. py:module:: target.need_mocks', '', '', '.. py:class:: TestAutodoc', - ' :module: autodoc_missing_imports', + ' :module: target.need_mocks', '', ' TestAutodoc docstring.', ' ', ' ', ' .. py:method:: TestAutodoc.decoratedMethod()', - ' :module: autodoc_missing_imports', + ' :module: target.need_mocks', ' ', ' TestAutodoc::decoratedMethod docstring', ' ', '', '.. py:function:: decoratedFunction()', - ' :module: autodoc_missing_imports', + ' :module: target.need_mocks', '', ' decoratedFunction docstring', ' ' ] + assert warning.getvalue() == '' @pytest.mark.usefixtures('setup_test') diff --git a/tests/test_build_texinfo.py b/tests/test_build_texinfo.py index a1af11df7..c14daf6ee 100644 --- a/tests/test_build_texinfo.py +++ b/tests/test_build_texinfo.py @@ -47,9 +47,9 @@ def test_texinfo(app, status, warning): TexinfoTranslator.ignore_missing_images = True app.builder.build_all() result = (app.outdir / 'SphinxTests.texi').text(encoding='utf8') - assert ('@anchor{markup doc}@anchor{12}' - '@anchor{markup id1}@anchor{13}' - '@anchor{markup testing-various-markup}@anchor{14}' in result) + assert ('@anchor{markup doc}@anchor{11}' + '@anchor{markup id1}@anchor{12}' + '@anchor{markup testing-various-markup}@anchor{13}' in result) # now, try to run makeinfo over it cwd = os.getcwd() os.chdir(app.outdir)