Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add missing type hints for tests.unittest. #13397

Merged
merged 11 commits into from
Jul 27, 2022
4 changes: 3 additions & 1 deletion tests/rest/client/test_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,10 @@ def test_get_state_cancellation(self) -> None:
)

self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.result["body"])
# json_body is defined as JsonDict, but it can be any valid JSON.
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
json_body: List[JsonDict] = channel.json_body # type: ignore[assignment]
self.assertCountEqual(
[state_event["type"] for state_event in channel.json_body],
[state_event["type"] for state_event in json_body],
{
"m.room.create",
"m.room.power_levels",
Expand Down
15 changes: 8 additions & 7 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Iterable,
List,
Optional,
NoReturn,
Tuple,
Type,
TypeVar,
Expand Down Expand Up @@ -194,31 +195,31 @@ def assert_dict(self, required: dict, actual: dict) -> None:
)


def DEBUG(target):
def DEBUG(target: TV) -> TV:
"""A decorator to set the .loglevel attribute to logging.DEBUG.
Can apply to either a TestCase or an individual test method."""
target.loglevel = logging.DEBUG
target.loglevel = logging.DEBUG # type: ignore[attr-defined]
return target


def INFO(target):
def INFO(target: TV) -> TV:
"""A decorator to set the .loglevel attribute to logging.INFO.
Can apply to either a TestCase or an individual test method."""
target.loglevel = logging.INFO
target.loglevel = logging.INFO # type: ignore[attr-defined]
return target


def logcontext_clean(target):
def logcontext_clean(target: TV) -> TV:
"""A decorator which marks the TestCase or method as 'logcontext_clean'

... ie, any logcontext errors should cause a test failure
"""

def logcontext_error(msg):
def logcontext_error(msg: str) -> NoReturn:
raise AssertionError("logcontext error: %s" % (msg))

patcher = patch("synapse.logging.context.logcontext_error", new=logcontext_error)
return patcher(target)
return patcher(target) # type: ignore[call-overload]


class HomeserverTestCase(TestCase):
Expand Down