Skip to content

Commit

Permalink
Fix mypy (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatMaul committed Oct 23, 2023
1 parent 4fcfb78 commit 49d2875
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 82 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
- run: python -m pip install tox
- run: tox -e check_codestyle

# check-types:
# name: Check types with Mypy
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.11"
# - run: python -m pip install tox
# - run: tox -e check_types
check-types:
name: Check types with Mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: python -m pip install tox
- run: tox -e check_types

unit-tests:
name: Unit tests
Expand Down
3 changes: 1 addition & 2 deletions manage_last_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
from typing import Any, Dict, Iterable, Optional, Tuple

import attr
from synapse.api.constants import EventTypes, Membership
from synapse.api.room_versions import EventFormatVersions, RoomVersion
from synapse.events import EventBase
from synapse.module_api import ModuleApi
from synapse.types import StateMap
from synapse.util.stringutils import random_string

from manage_last_admin._constants import EventTypes, Membership

logger = logging.getLogger(__name__)


Expand Down
60 changes: 0 additions & 60 deletions manage_last_admin/_constants.py

This file was deleted.

21 changes: 11 additions & 10 deletions tests/test_manage_last_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
# unittest.IsolatedAsyncioTestCase, so we'll be able to get rid of this dependency when
# we stop supporting Python < 3.8 in Synapse.
from abc import abstractmethod
from typing import Any, Dict

import aiounittest
from synapse.api.constants import EventTypes, Membership
from synapse.api.room_versions import RoomVersions
from synapse.events import EventBase, make_event_from_dict
from synapse.types import JsonDict
from synapse.util.stringutils import random_string

from manage_last_admin import EventTypes, Membership
from tests import create_module


Expand Down Expand Up @@ -122,8 +123,8 @@ async def test_power_levels_sent_when_last_admin_leaves(self) -> None:
self.assertEqual(replacement, None)

# Test that the leave triggered a freeze of the room.
self.assertTrue(module._api.create_and_send_event_into_room.called)
args, _ = module._api.create_and_send_event_into_room.call_args
self.assertTrue(module._api.create_and_send_event_into_room.called) # type: ignore[attr-defined]
args, _ = module._api.create_and_send_event_into_room.call_args # type: ignore[attr-defined]
self.assertEqual(len(args), 1)

pl_event_dict = args[0]
Expand Down Expand Up @@ -158,15 +159,15 @@ async def test_promote_when_last_admin_leaves(self) -> None:
self.assertEqual(replacement, None)

# Test that a new event was sent into the room.
self.assertTrue(module._api.create_and_send_event_into_room.called)
args, _ = module._api.create_and_send_event_into_room.call_args
self.assertTrue(module._api.create_and_send_event_into_room.called) # type: ignore[attr-defined]
args, _ = module._api.create_and_send_event_into_room.call_args # type: ignore[attr-defined]
self.assertEqual(len(args), 1)

# Test that:
# * the event is a power levels update
# * the user who is PL 75 but left the room didn't get promoted
# * the user who was PL 50 and is still in the room got promoted
evt_dict: dict = args[0]
evt_dict: Dict[str, Any] = args[0]
self.assertEqual(evt_dict["type"], EventTypes.PowerLevels, evt_dict)
self.assertIsNotNone(evt_dict.get("state_key"))
self.assertEqual(
Expand Down Expand Up @@ -201,8 +202,8 @@ async def test_promote_when_last_admin_leaves(self) -> None:
self.assertEqual(replacement, None)

# Test that a new event was sent into the room.
self.assertTrue(module._api.create_and_send_event_into_room.called)
args, _ = module._api.create_and_send_event_into_room.call_args
self.assertTrue(module._api.create_and_send_event_into_room.called) # type: ignore[attr-defined]
args, _ = module._api.create_and_send_event_into_room.call_args # type: ignore[attr-defined]
self.assertEqual(len(args), 1)

# Test that now that there's no user to promote anymore, the room default user level is 100.
Expand All @@ -214,11 +215,11 @@ async def test_promote_when_last_admin_leaves(self) -> None:


class ManageLastAdminTestRoomV9(ManageLastAdminTestCases.BaseManageLastAdminTest):
def create_event(self, content: JsonDict):
def create_event(self, content: JsonDict) -> EventBase:
return make_event_from_dict(content, RoomVersions.V9)


class ManageLastAdminTestRoomV1(ManageLastAdminTestCases.BaseManageLastAdminTest):
def create_event(self, content: JsonDict):
def create_event(self, content: JsonDict) -> EventBase:
content["event_id"] = f"!{random_string(43)}:example.com"
return make_event_from_dict(content, RoomVersions.V1)

0 comments on commit 49d2875

Please sign in to comment.