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
from io import StringIO
from unittest.mock import Mock, patch
from xml.etree.ElementTree import Element
import pytest
from docutils import nodes
@ -45,7 +46,7 @@ def _unload_target_module():
def test_mangle_signature():
TEST = """
TEST_SIGNATURE = """
() :: ()
(a, b, c, d, e) :: (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)
"""
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:
res = mangle_signature(inp).strip().replace('\u00a0', ' ')
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
def str_content(elem):
def str_content(elem: Element) -> str:
if elem.text is not None:
return elem.text
else:

View File

@ -2,6 +2,7 @@
import functools
from collections import namedtuple
from typing import Any
from unittest import mock
import pytest
@ -141,7 +142,14 @@ class TestSetup:
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
app = mock.Mock()
app.config = Config()

View File

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