Skip to content

Commit

Permalink
Resolve a few mypy issues in tests (#12912)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
adamtheturtle and AA-Turner committed Sep 25, 2024
1 parent 914f3f4 commit 7487e76
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
11 changes: 8 additions & 3 deletions tests/test_extensions/test_ext_autosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand All @@ -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}'"
Expand Down Expand Up @@ -206,7 +211,7 @@ def handler(app, what, name, obj, options, lines):
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:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_extensions/test_ext_napoleon.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import functools
from collections import namedtuple
from typing import Any
from unittest import mock

import pytest
Expand Down Expand Up @@ -141,7 +142,14 @@ def test_add_config_values(self):


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()
Expand Down
11 changes: 7 additions & 4 deletions tests/test_util/test_util_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import warnings
from textwrap import dedent
from typing import Any
from typing import TYPE_CHECKING, Any

import pytest
from docutils import frontend, nodes
Expand All @@ -21,12 +21,15 @@
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
Expand All @@ -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:
Expand Down

0 comments on commit 7487e76

Please sign in to comment.