Resolve a few mypy issues in tests (#12912)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Adam Dangoor 2024-09-25 08:57:11 +01:00 committed by GitHub
parent 914f3f4e54
commit 7487e764cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 8 deletions

View File

@ -3,6 +3,7 @@
import sys import sys
from io import StringIO from io import StringIO
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from xml.etree.ElementTree import Element
import pytest import pytest
from docutils import nodes from docutils import nodes
@ -45,7 +46,7 @@ def _unload_target_module():
def test_mangle_signature(): def test_mangle_signature():
TEST = """ TEST_SIGNATURE = """
() :: () () :: ()
(a, b, c, d, e) :: (a, b, c, d, e) (a, b, c, d, e) :: (a, b, c, d, e)
(a, b, c=1, d=2, e=3) :: (a, b[, c, d, e]) (a, b, c=1, d=2, e=3) :: (a, b[, c, d, e])
@ -66,7 +67,11 @@ def test_mangle_signature():
(a: Tuple[int, str], b: int) -> str :: (a, b) (a: Tuple[int, str], b: int) -> str :: (a, b)
""" """
TEST = [[y.strip() for y in x.split('::')] for x in TEST.split('\n') if '::' in x] TEST = [
list(map(str.strip, x.split('::')))
for x in TEST_SIGNATURE.split('\n')
if '::' in x
]
for inp, outp in TEST: for inp, outp in TEST:
res = mangle_signature(inp).strip().replace('\u00a0', ' ') res = mangle_signature(inp).strip().replace('\u00a0', ' ')
assert res == outp, f"'{inp}' -> '{res}' != '{outp}'" assert res == outp, f"'{inp}' -> '{res}' != '{outp}'"
@ -206,7 +211,7 @@ def test_get_items_summary(make_app, app_params):
assert autosummary_items['func'] == func_attrs assert autosummary_items['func'] == func_attrs
def str_content(elem): def str_content(elem: Element) -> str:
if elem.text is not None: if elem.text is not None:
return elem.text return elem.text
else: else:

View File

@ -2,6 +2,7 @@
import functools import functools
from collections import namedtuple from collections import namedtuple
from typing import Any
from unittest import mock from unittest import mock
import pytest import pytest
@ -141,7 +142,14 @@ class TestSetup:
class TestSkipMember: class TestSkipMember:
def assert_skip(self, what, member, obj, expect_default_skip, config_name): def assert_skip(
self,
what: str,
member: str,
obj: Any,
expect_default_skip: bool,
config_name: str,
) -> None:
skip = True skip = True
app = mock.Mock() app = mock.Mock()
app.config = Config() app.config = Config()

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import warnings import warnings
from textwrap import dedent from textwrap import dedent
from typing import Any from typing import TYPE_CHECKING, Any
import pytest import pytest
from docutils import frontend, nodes from docutils import frontend, nodes
@ -21,12 +21,15 @@ from sphinx.util.nodes import (
split_explicit_title, split_explicit_title,
) )
if TYPE_CHECKING:
from docutils.nodes import document
def _transform(doctree):
def _transform(doctree) -> None:
ApplySourceWorkaround(doctree).apply() ApplySourceWorkaround(doctree).apply()
def create_new_document(): def create_new_document() -> document:
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning) warnings.filterwarnings('ignore', category=DeprecationWarning)
# DeprecationWarning: The frontend.OptionParser class will be replaced # DeprecationWarning: The frontend.OptionParser class will be replaced
@ -44,7 +47,7 @@ def _get_doctree(text):
return document return document
def assert_node_count(messages, node_type, expect_count): def assert_node_count(messages, node_type, expect_count) -> None:
count = 0 count = 0
node_list = [node for node, msg in messages] node_list = [node for node, msg in messages]
for node in node_list: for node in node_list: