mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6143 from tk0miya/6140_unittest.mock
Fix #6140: Use unittest.mock instead of mock
This commit is contained in:
commit
e8195d24c7
1
CHANGES
1
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
|
||||
--------
|
||||
|
1
setup.py
1
setup.py
@ -39,7 +39,6 @@ extras_require = {
|
||||
'colorama>=0.3.5',
|
||||
],
|
||||
'test': [
|
||||
'mock',
|
||||
'pytest',
|
||||
'pytest-cov',
|
||||
'html5lib',
|
||||
|
@ -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)
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
import sys
|
||||
from textwrap import dedent
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from docutils import nodes
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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='',
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user