summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-03-08 00:56:45 +0900
committerGitHub <noreply@github.com>2019-03-08 00:56:45 +0900
commite8195d24c7076c01a95e1460338b0fff901c824b (patch)
tree0a0bd0448163cc7ba71163dff4b29cef3619ea1c
parentba86f4ea7895ff59368a602d43bb85fc4d453546 (diff)
parentc83f2a0272f3178342918c27985b9098844314a0 (diff)
downloadsphinx-git-e8195d24c7076c01a95e1460338b0fff901c824b.tar.gz
Merge pull request #6143 from tk0miya/6140_unittest.mock
Fix #6140: Use unittest.mock instead of mock
-rw-r--r--CHANGES1
-rw-r--r--setup.py1
-rw-r--r--sphinx/domains/cpp.py53
-rw-r--r--tests/test_build.py2
-rw-r--r--tests/test_config.py10
-rw-r--r--tests/test_domain_js.py3
-rw-r--r--tests/test_domain_py.py3
-rw-r--r--tests/test_domain_std.py3
-rw-r--r--tests/test_environment_indexentries.py3
-rw-r--r--tests/test_ext_autosummary.py4
-rw-r--r--tests/test_ext_intersphinx.py2
-rw-r--r--tests/test_ext_napoleon.py4
-rw-r--r--tests/test_ext_napoleon_docstring.py4
-rw-r--r--tests/test_highlighting.py3
-rw-r--r--tests/test_roles.py3
-rw-r--r--tests/test_util.py2
-rw-r--r--tests/test_util_fileutil.py2
17 files changed, 52 insertions, 51 deletions
diff --git a/CHANGES b/CHANGES
index a88b668ed..db935d669 100644
--- a/CHANGES
+++ b/CHANGES
@@ -64,6 +64,7 @@ Bugs fixed
* texinfo: ``make install-info`` fails on macOS
* #3079: texinfo: image files are not copied on ``make install-info``
* #5391: A cross reference in heading is rendered as literal
+* #5946: C++, fix ``cpp:alias`` problems in LaTeX (and singlehtml)
Testing
--------
diff --git a/setup.py b/setup.py
index 79c466321..eccceebb3 100644
--- a/setup.py
+++ b/setup.py
@@ -39,7 +39,6 @@ extras_require = {
'colorama>=0.3.5',
],
'test': [
- 'mock',
'pytest',
'pytest-cov',
'html5lib',
diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py
index 01432abb5..e60f61f2c 100644
--- a/sphinx/domains/cpp.py
+++ b/sphinx/domains/cpp.py
@@ -6734,27 +6734,20 @@ class CPPNamespacePopObject(SphinxDirective):
class AliasNode(nodes.Element):
- def __init__(self, sig, warnEnv):
- """
- :param sig: The name or function signature to alias.
- :param warnEnv: An object which must have the following attributes:
- env: a Sphinx environment
- whatever DefinitionParser requires of warnEnv
- """
+ def __init__(self, sig, env=None, parentKey=None):
super().__init__()
self.sig = sig
- env = warnEnv.env
- if 'cpp:parent_symbol' not in env.temp_data:
- root = env.domaindata['cpp']['root_symbol']
- env.temp_data['cpp:parent_symbol'] = root
- self.parentKey = env.temp_data['cpp:parent_symbol'].get_lookup_key()
- try:
- parser = DefinitionParser(sig, warnEnv, warnEnv.env.config)
- self.ast, self.isShorthand = parser.parse_xref_object()
- parser.assert_end()
- except DefinitionError as e:
- warnEnv.warn(e)
- self.ast = None
+ if env is not None:
+ if 'cpp:parent_symbol' not in env.temp_data:
+ root = env.domaindata['cpp']['root_symbol']
+ env.temp_data['cpp:parent_symbol'] = root
+ self.parentKey = env.temp_data['cpp:parent_symbol'].get_lookup_key()
+ else:
+ assert parentKey is not None
+ self.parentKey = parentKey
+
+ def copy(self):
+ return self.__class__(self.sig, env=None, parentKey=self.parentKey)
class AliasTransform(SphinxTransform):
@@ -6763,8 +6756,20 @@ class AliasTransform(SphinxTransform):
def apply(self, **kwargs):
# type: (Any) -> None
for node in self.document.traverse(AliasNode):
+ class Warner:
+ def warn(self, msg):
+ logger.warning(msg, location=node)
+ warner = Warner()
sig = node.sig
- ast = node.ast
+ parentKey = node.parentKey
+ try:
+ parser = DefinitionParser(sig, warner, self.env.config)
+ ast, isShorthand = parser.parse_xref_object()
+ parser.assert_end()
+ except DefinitionError as e:
+ warner.warn(e)
+ ast, isShorthand = None, None
+
if ast is None:
# could not be parsed, so stop here
signode = addnodes.desc_signature(sig, '')
@@ -6774,8 +6779,6 @@ class AliasTransform(SphinxTransform):
node.replace_self(signode)
continue
- isShorthand = node.isShorthand
- parentKey = node.parentKey
rootSymbol = self.env.domains['cpp'].data['root_symbol']
parentSymbol = rootSymbol.direct_lookup(parentKey)
if not parentSymbol:
@@ -6833,10 +6836,6 @@ class AliasTransform(SphinxTransform):
class CPPAliasObject(ObjectDescription):
option_spec = {} # type: Dict
- def warn(self, msg):
- # type: (Union[str, Exception]) -> None
- self.state_machine.reporter.warning(msg, line=self.lineno)
-
def run(self):
# type: () -> List[nodes.Node]
"""
@@ -6859,7 +6858,7 @@ class CPPAliasObject(ObjectDescription):
self.names = [] # type: List[str]
signatures = self.get_signatures()
for i, sig in enumerate(signatures):
- node.append(AliasNode(sig, self))
+ node.append(AliasNode(sig, env=self.env))
contentnode = addnodes.desc_content()
node.append(contentnode)
diff --git a/tests/test_build.py b/tests/test_build.py
index 8072906a2..fa620d352 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -10,8 +10,8 @@
import sys
from textwrap import dedent
+from unittest import mock
-import mock
import pytest
from docutils import nodes
diff --git a/tests/test_config.py b/tests/test_config.py
index fadf7d6c4..a5da0d6ec 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -8,7 +8,9 @@
:copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
-import mock
+
+from unittest import mock
+
import pytest
import sphinx
@@ -257,7 +259,7 @@ def test_conf_warning_message(logger, name, default, annotation, actual, message
config.add(name, default, False, annotation or ())
config.init_values()
check_confval_types(None, config)
- logger.warning.assert_called()
+ assert logger.warning.called
assert logger.warning.call_args[0][0] == message
@@ -276,7 +278,7 @@ def test_check_enum_failed(logger):
config.add('value', 'default', False, ENUM('default', 'one', 'two'))
config.init_values()
check_confval_types(None, config)
- logger.warning.assert_called()
+ assert logger.warning.called
@mock.patch("sphinx.config.logger")
@@ -294,4 +296,4 @@ def test_check_enum_for_list_failed(logger):
config.add('value', 'default', False, ENUM('default', 'one', 'two'))
config.init_values()
check_confval_types(None, config)
- logger.warning.assert_called()
+ assert logger.warning.called
diff --git a/tests/test_domain_js.py b/tests/test_domain_js.py
index 174a431bf..613623ee5 100644
--- a/tests/test_domain_js.py
+++ b/tests/test_domain_js.py
@@ -8,9 +8,10 @@
:license: BSD, see LICENSE for details.
"""
+from unittest.mock import Mock
+
import pytest
from docutils import nodes
-from mock import Mock
from sphinx import addnodes
from sphinx.domains.javascript import JavaScriptDomain
diff --git a/tests/test_domain_py.py b/tests/test_domain_py.py
index ff6387101..c4a50b742 100644
--- a/tests/test_domain_py.py
+++ b/tests/test_domain_py.py
@@ -8,9 +8,10 @@
:license: BSD, see LICENSE for details.
"""
+from unittest.mock import Mock
+
import pytest
from docutils import nodes
-from mock import Mock
from sphinx import addnodes
from sphinx.domains.python import py_sig_re, _pseudo_parse_arglist, PythonDomain
diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py
index dda8a4313..15daeeea6 100644
--- a/tests/test_domain_std.py
+++ b/tests/test_domain_std.py
@@ -8,7 +8,8 @@
:license: BSD, see LICENSE for details.
"""
-import mock
+from unittest import mock
+
from docutils import nodes
from sphinx.domains.std import StandardDomain
diff --git a/tests/test_environment_indexentries.py b/tests/test_environment_indexentries.py
index 4475fb273..62e4ffb79 100644
--- a/tests/test_environment_indexentries.py
+++ b/tests/test_environment_indexentries.py
@@ -9,8 +9,7 @@
"""
from collections import namedtuple
-
-import mock
+from unittest import mock
from sphinx import locale
from sphinx.environment.adapters.indexentries import IndexEntries
diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py
index 63026beb5..3cc9710d8 100644
--- a/tests/test_ext_autosummary.py
+++ b/tests/test_ext_autosummary.py
@@ -10,11 +10,13 @@
import sys
from io import StringIO
+from unittest.mock import Mock
import pytest
from sphinx.ext.autosummary import mangle_signature, import_by_name, extract_summary
from sphinx.testing.util import etree_parse
+from sphinx.util.docutils import new_document
html_warnfile = StringIO()
@@ -57,8 +59,6 @@ def test_mangle_signature():
def test_extract_summary(capsys):
- from sphinx.util.docutils import new_document
- from mock import Mock
settings = Mock(language_code='',
id_prefix='',
auto_id_prefix='',
diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py
index 45684123f..93bf16834 100644
--- a/tests/test_ext_intersphinx.py
+++ b/tests/test_ext_intersphinx.py
@@ -11,8 +11,8 @@
import os
import unittest
from io import BytesIO
+from unittest import mock
-import mock
import pytest
import requests
from docutils import nodes
diff --git a/tests/test_ext_napoleon.py b/tests/test_ext_napoleon.py
index 9127109d9..19eb536fa 100644
--- a/tests/test_ext_napoleon.py
+++ b/tests/test_ext_napoleon.py
@@ -10,9 +10,7 @@
"""
from collections import namedtuple
-from unittest import TestCase
-
-import mock
+from unittest import TestCase, mock
from sphinx.application import Sphinx
from sphinx.ext.napoleon import _process_docstring, _skip_member, Config, setup
diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py
index 71ac1870e..fa75062b3 100644
--- a/tests/test_ext_napoleon_docstring.py
+++ b/tests/test_ext_napoleon_docstring.py
@@ -12,9 +12,7 @@
from collections import namedtuple
from inspect import cleandoc
from textwrap import dedent
-from unittest import TestCase
-
-import mock
+from unittest import TestCase, mock
from sphinx.ext.napoleon import Config
from sphinx.ext.napoleon.docstring import GoogleDocstring, NumpyDocstring
diff --git a/tests/test_highlighting.py b/tests/test_highlighting.py
index efe2871c8..fca51d02f 100644
--- a/tests/test_highlighting.py
+++ b/tests/test_highlighting.py
@@ -8,7 +8,8 @@
:license: BSD, see LICENSE for details.
"""
-import mock
+from unittest import mock
+
from pygments.formatters.html import HtmlFormatter
from pygments.lexer import RegexLexer
from pygments.token import Text, Name
diff --git a/tests/test_roles.py b/tests/test_roles.py
index eb4cf4ecf..8f0e546b6 100644
--- a/tests/test_roles.py
+++ b/tests/test_roles.py
@@ -8,8 +8,9 @@
:license: BSD, see LICENSE for details.
"""
+from unittest.mock import Mock
+
from docutils import nodes
-from mock import Mock
from sphinx.roles import EmphasizedLiteral
from sphinx.testing.util import assert_node
diff --git a/tests/test_util.py b/tests/test_util.py
index bcac4b654..44a41dca1 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -10,9 +10,9 @@
import os
import tempfile
+from unittest.mock import patch
import pytest
-from mock import patch
import sphinx
from sphinx.errors import ExtensionError, PycodeError
diff --git a/tests/test_util_fileutil.py b/tests/test_util_fileutil.py
index 635559efa..7e0d261bd 100644
--- a/tests/test_util_fileutil.py
+++ b/tests/test_util_fileutil.py
@@ -8,7 +8,7 @@
:license: BSD, see LICENSE for details.
"""
-import mock
+from unittest import mock
from sphinx.jinja2glue import BuiltinTemplateLoader
from sphinx.util.fileutil import copy_asset, copy_asset_file