diff --git a/tests/commands/test_handler.py b/tests/commands/test_handler.py index a88e8661..1e006db6 100644 --- a/tests/commands/test_handler.py +++ b/tests/commands/test_handler.py @@ -6,9 +6,8 @@ from _pytest.fixtures import FixtureRequest from pytest_mock import MockFixture import mautrix_telegram.commands.handler -from mautrix_telegram.commands.handler import ( - CommandEvent, CommandHandler, CommandProcessor, HelpSection -) +from mautrix_telegram.commands.handler import (CommandEvent, CommandHandler, CommandProcessor, + HelpSection) from mautrix_telegram.config import Config from mautrix_telegram.context import Context from mautrix_telegram.types import MatrixEventID, MatrixRoomID, MatrixUserID @@ -25,13 +24,7 @@ def context(request: FixtureRequest) -> Context: """ # Config(path, registration_path, base_path) config = getattr(request.cls, 'config', Config("", "", "")) - return Context( - Mock(), # az - Mock(), # db - config, # config - Mock(), # loop - Mock() # session_container - ) + return Context(az=Mock(), config=config, loop=Mock(), session_container=Mock(), bot=Mock()) @pytest.fixture @@ -97,15 +90,12 @@ class TestCommandEvent: mock_az.intent.send_notice.assert_called_with( MatrixRoomID("#mock_room:example.org"), "**This** was
allfun*!", - html=( - "

This <i>was</i><br/>" - "<strong>all</strong>fun*!

\n" - ), + html="

This <i>was</i><br/>" + "<strong>all</strong>fun*!

\n" ) - def test_reply_with_cmdprefix( - self, command_processor: CommandProcessor, mocker: MockFixture - ) -> None: + def test_reply_with_cmdprefix(self, command_processor: CommandProcessor, mocker: MockFixture + ) -> None: mocker.patch("mautrix_telegram.user.config", self.config) evt = CommandEvent( @@ -121,11 +111,8 @@ class TestCommandEvent: mock_az = command_processor.az - evt.reply( - "$cmdprefix+sp ....$cmdprefix+sp...$cmdprefix $cmdprefix", - allow_html=False, - render_markdown=False, - ) + evt.reply("$cmdprefix+sp ....$cmdprefix+sp...$cmdprefix $cmdprefix", allow_html=False, + render_markdown=False) mock_az.intent.send_notice.assert_called_with( MatrixRoomID("#mock_room:example.org"), @@ -133,9 +120,8 @@ class TestCommandEvent: html=None, ) - def test_reply_with_cmdprefix_in_management_room( - self, command_processor: CommandProcessor, mocker: MockFixture - ) -> None: + def test_reply_with_cmdprefix_in_management_room(self, command_processor: CommandProcessor, + mocker: MockFixture) -> None: mocker.patch("mautrix_telegram.user.config", self.config) evt = CommandEvent( @@ -163,6 +149,7 @@ class TestCommandEvent: html="

....tg+sp...tg tg

\n", ) + class TestCommandHandler: config = Config("", "", "") config["bridge.permissions"] = {"*": "noperm"} @@ -301,12 +288,8 @@ class TestCommandProcessor: config["bridge.permissions"] = {"*": "relaybot"} @pytest.mark.asyncio - async def test_handle( - self, - command_processor: CommandProcessor, - boolean2: Tuple[bool, bool], - mocker: MockFixture, - ) -> None: + async def test_handle(self, command_processor: CommandProcessor, boolean2: Tuple[bool, bool], + mocker: MockFixture) -> None: mocker.patch('mautrix_telegram.user.config', self.config) mocker.patch( 'mautrix_telegram.commands.handler.command_handlers', @@ -330,12 +313,8 @@ class TestCommandProcessor: command_handlers["help"].mock.assert_called_once() # type: ignore @pytest.mark.asyncio - async def test_handle_unknown_command( - self, - command_processor: CommandProcessor, - boolean2: Tuple[bool, bool], - mocker: MockFixture, - ) -> None: + async def test_handle_unknown_command(self, command_processor: CommandProcessor, + boolean2: Tuple[bool, bool], mocker: MockFixture) -> None: mocker.patch('mautrix_telegram.user.config', self.config) mocker.patch( 'mautrix_telegram.commands.handler.command_handlers', @@ -361,12 +340,9 @@ class TestCommandProcessor: command_handlers["unknown-command"].mock.assert_called_once() # type: ignore @pytest.mark.asyncio - async def test_handle_delegated_handler( - self, - command_processor: CommandProcessor, - boolean2: Tuple[bool, bool], - mocker: MockFixture, - ) -> None: + async def test_handle_delegated_handler(self, command_processor: CommandProcessor, + boolean2: Tuple[bool, bool], + mocker: MockFixture) -> None: mocker.patch('mautrix_telegram.user.config', self.config) mocker.patch( 'mautrix_telegram.commands.handler.command_handlers', diff --git a/tests/utils/fixtures.py b/tests/utils/fixtures.py index 3c272750..e0953da7 100644 --- a/tests/utils/fixtures.py +++ b/tests/utils/fixtures.py @@ -12,19 +12,16 @@ def boolean(request: FixtureRequest) -> bool: @pytest.fixture def boolean1(boolean: bool) -> Tuple[bool]: - return (boolean,) + return boolean, @pytest.fixture(params=[True, False]) def boolean2(request: FixtureRequest, boolean: bool) -> Tuple[bool, bool]: - return (boolean, request.param) + return boolean, request.param @pytest.fixture(params=[True, False]) -def boolean3( - request: FixtureRequest, boolean2: Tuple[bool, bool] -) -> Tuple[bool, bool, bool]: - return (boolean2[0], boolean2[1], request.param) - +def boolean3(request: FixtureRequest, boolean2: Tuple[bool, bool]) -> Tuple[bool, bool, bool]: + return boolean2[0], boolean2[1], request.param # …