From d3d84685ce1acc05cbec00d2934548473850f9d0 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 17 Jun 2022 08:38:13 -0400 Subject: [PATCH] Add type hints to event push actions tests. (#13099) --- changelog.d/12985.misc | 2 +- changelog.d/13099.misc | 1 + tests/storage/test_event_push_actions.py | 28 ++++++++++++++---------- 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 changelog.d/13099.misc diff --git a/changelog.d/12985.misc b/changelog.d/12985.misc index d5ab9eedea81..7f6492d5875b 100644 --- a/changelog.d/12985.misc +++ b/changelog.d/12985.misc @@ -1 +1 @@ -Add type annotations to `tests.state.test_v2`. +Add type hints to tests. diff --git a/changelog.d/13099.misc b/changelog.d/13099.misc new file mode 100644 index 000000000000..7f6492d5875b --- /dev/null +++ b/changelog.d/13099.misc @@ -0,0 +1 @@ +Add type hints to tests. diff --git a/tests/storage/test_event_push_actions.py b/tests/storage/test_event_push_actions.py index 4273524c4c3f..2ac5f6db5e74 100644 --- a/tests/storage/test_event_push_actions.py +++ b/tests/storage/test_event_push_actions.py @@ -14,7 +14,11 @@ from unittest.mock import Mock +from twisted.test.proto_helpers import MemoryReactor + +from synapse.server import HomeServer from synapse.storage.databases.main.event_push_actions import NotifCounts +from synapse.util import Clock from tests.unittest import HomeserverTestCase @@ -29,31 +33,33 @@ class EventPushActionsStoreTestCase(HomeserverTestCase): - def prepare(self, reactor, clock, hs): + def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.store = hs.get_datastores().main - self.persist_events_store = hs.get_datastores().persist_events + persist_events_store = hs.get_datastores().persist_events + assert persist_events_store is not None + self.persist_events_store = persist_events_store - def test_get_unread_push_actions_for_user_in_range_for_http(self): + def test_get_unread_push_actions_for_user_in_range_for_http(self) -> None: self.get_success( self.store.get_unread_push_actions_for_user_in_range_for_http( USER_ID, 0, 1000, 20 ) ) - def test_get_unread_push_actions_for_user_in_range_for_email(self): + def test_get_unread_push_actions_for_user_in_range_for_email(self) -> None: self.get_success( self.store.get_unread_push_actions_for_user_in_range_for_email( USER_ID, 0, 1000, 20 ) ) - def test_count_aggregation(self): + def test_count_aggregation(self) -> None: room_id = "!foo:example.com" user_id = "@user1235:example.com" last_read_stream_ordering = [0] - def _assert_counts(noitf_count, highlight_count): + def _assert_counts(noitf_count: int, highlight_count: int) -> None: counts = self.get_success( self.store.db_pool.runInteraction( "", @@ -72,7 +78,7 @@ def _assert_counts(noitf_count, highlight_count): ), ) - def _inject_actions(stream, action): + def _inject_actions(stream: int, action: list) -> None: event = Mock() event.room_id = room_id event.event_id = "$test:example.com" @@ -96,14 +102,14 @@ def _inject_actions(stream, action): ) ) - def _rotate(stream): + def _rotate(stream: int) -> None: self.get_success( self.store.db_pool.runInteraction( "", self.store._rotate_notifs_before_txn, stream ) ) - def _mark_read(stream, depth): + def _mark_read(stream: int, depth: int) -> None: last_read_stream_ordering[0] = stream self.get_success( self.store.db_pool.runInteraction( @@ -165,8 +171,8 @@ def _mark_read(stream, depth): _mark_read(10, 10) _assert_counts(0, 0) - def test_find_first_stream_ordering_after_ts(self): - def add_event(so, ts): + def test_find_first_stream_ordering_after_ts(self) -> None: + def add_event(so: int, ts: int) -> None: self.get_success( self.store.db_pool.simple_insert( "events",