Reformat code

This commit is contained in:
JRoot Junior 2024-10-19 14:32:20 +03:00
parent a98e5871d2
commit 3ee8d903da
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
4 changed files with 60 additions and 40 deletions

View file

@ -248,13 +248,16 @@ class TestAiohttpSession:
async with AiohttpSession() as session: async with AiohttpSession() as session:
assert isinstance(session, AsyncContextManager) assert isinstance(session, AsyncContextManager)
with patch( with (
"aiogram.client.session.aiohttp.AiohttpSession.create_session", patch(
new_callable=AsyncMock, "aiogram.client.session.aiohttp.AiohttpSession.create_session",
) as mocked_create_session, patch( new_callable=AsyncMock,
"aiogram.client.session.aiohttp.AiohttpSession.close", ) as mocked_create_session,
new_callable=AsyncMock, patch(
) as mocked_close: "aiogram.client.session.aiohttp.AiohttpSession.close",
new_callable=AsyncMock,
) as mocked_close,
):
async with session as ctx: async with session as ctx:
assert session == ctx assert session == ctx
mocked_close.assert_awaited_once() mocked_close.assert_awaited_once()

View file

@ -778,11 +778,14 @@ class TestDispatcher:
async def _mock_updates(*_): async def _mock_updates(*_):
yield Update(update_id=42) yield Update(update_id=42)
with patch( with (
"aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock patch(
) as mocked_process_update, patch( "aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates" ) as mocked_process_update,
) as patched_listen_updates: patch(
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
) as patched_listen_updates,
):
patched_listen_updates.return_value = _mock_updates() patched_listen_updates.return_value = _mock_updates()
await dispatcher._polling(bot=bot, handle_as_tasks=as_task) await dispatcher._polling(bot=bot, handle_as_tasks=as_task)
if as_task: if as_task:
@ -852,15 +855,20 @@ class TestDispatcher:
async def _mock_updates(*_): async def _mock_updates(*_):
yield Update(update_id=42) yield Update(update_id=42)
with patch( with (
"aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock patch(
) as mocked_process_update, patch( "aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock
"aiogram.dispatcher.router.Router.emit_startup", new_callable=AsyncMock ) as mocked_process_update,
) as mocked_emit_startup, patch( patch(
"aiogram.dispatcher.router.Router.emit_shutdown", new_callable=AsyncMock "aiogram.dispatcher.router.Router.emit_startup", new_callable=AsyncMock
) as mocked_emit_shutdown, patch( ) as mocked_emit_startup,
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates" patch(
) as patched_listen_updates: "aiogram.dispatcher.router.Router.emit_shutdown", new_callable=AsyncMock
) as mocked_emit_shutdown,
patch(
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
) as patched_listen_updates,
):
patched_listen_updates.return_value = _mock_updates() patched_listen_updates.return_value = _mock_updates()
await dispatcher.start_polling(bot) await dispatcher.start_polling(bot)
@ -916,11 +924,14 @@ class TestDispatcher:
yield Update(update_id=42) yield Update(update_id=42)
await asyncio.sleep(1) await asyncio.sleep(1)
with patch( with (
"aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock patch(
) as mocked_process_update, patch( "aiogram.dispatcher.dispatcher.Dispatcher._process_update", new_callable=AsyncMock
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates", ) as mocked_process_update,
return_value=_mock_updates(), patch(
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates",
return_value=_mock_updates(),
),
): ):
task = asyncio.ensure_future(dispatcher.start_polling(bot)) task = asyncio.ensure_future(dispatcher.start_polling(bot))
await running.wait() await running.wait()

View file

@ -198,13 +198,16 @@ class TestCallbackAnswerMiddleware:
stack.append("answer") stack.append("answer")
middleware = CallbackAnswerMiddleware() middleware = CallbackAnswerMiddleware()
with patch( with (
"aiogram.utils.callback_answer.CallbackAnswerMiddleware.construct_callback_answer", patch(
new_callable=MagicMock, "aiogram.utils.callback_answer.CallbackAnswerMiddleware.construct_callback_answer",
side_effect=lambda **kwargs: CallbackAnswer(**{"answered": False, **properties}), new_callable=MagicMock,
), patch( side_effect=lambda **kwargs: CallbackAnswer(**{"answered": False, **properties}),
"aiogram.utils.callback_answer.CallbackAnswerMiddleware.answer", ),
new=answer, patch(
"aiogram.utils.callback_answer.CallbackAnswerMiddleware.answer",
new=answer,
),
): ):
await middleware(handler, event, {}) await middleware(handler, event, {})

View file

@ -96,13 +96,16 @@ class TestChatActionMiddleware:
handler1 = flags.chat_action(value)(handler) handler1 = flags.chat_action(value)(handler)
middleware = ChatActionMiddleware() middleware = ChatActionMiddleware()
with patch( with (
"aiogram.utils.chat_action.ChatActionSender._run", patch(
new_callable=AsyncMock, "aiogram.utils.chat_action.ChatActionSender._run",
) as mocked_run, patch( new_callable=AsyncMock,
"aiogram.utils.chat_action.ChatActionSender._stop", ) as mocked_run,
new_callable=AsyncMock, patch(
) as mocked_stop: "aiogram.utils.chat_action.ChatActionSender._stop",
new_callable=AsyncMock,
) as mocked_stop,
):
data = {"handler": HandlerObject(callback=handler1), "bot": bot} data = {"handler": HandlerObject(callback=handler1), "bot": bot}
message = Message( message = Message(
chat=Chat(id=42, type="private", title="Test"), chat=Chat(id=42, type="private", title="Test"),