mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Make Dispatcher._run_polling public
This commit is contained in:
parent
1d2c6c91d0
commit
a2cb637ed9
3 changed files with 8 additions and 8 deletions
2
Makefile
2
Makefile
|
|
@ -1,6 +1,6 @@
|
|||
.DEFAULT_GOAL := help
|
||||
|
||||
base_python := python3.7
|
||||
base_python := python3
|
||||
py := poetry run
|
||||
python := $(py) python
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class Dispatcher(Router):
|
|||
async for update in self._listen_updates(bot):
|
||||
await self.process_update(update=update, bot=bot, **kwargs)
|
||||
|
||||
async def _run_polling(self, *bots: Bot, **kwargs: Any) -> None:
|
||||
async def start_polling(self, *bots: Bot, **kwargs: Any) -> None:
|
||||
"""
|
||||
Polling runner
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ class Dispatcher(Router):
|
|||
:return:
|
||||
"""
|
||||
try:
|
||||
return asyncio.run(self._run_polling(*bots, **kwargs))
|
||||
return asyncio.run(self.start_polling(*bots, **kwargs))
|
||||
except (KeyboardInterrupt, SystemExit): # pragma: no cover
|
||||
# Allow to graceful shutdown
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class TestDispatcher:
|
|||
mocked_process_update.assert_awaited()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_polling(self, bot: MockedBot):
|
||||
async def test_start_polling(self, bot: MockedBot):
|
||||
dispatcher = Dispatcher()
|
||||
bot.add_result_for(
|
||||
GetMe, ok=True, result=User(id=42, is_bot=True, first_name="The bot", username="tbot")
|
||||
|
|
@ -183,14 +183,14 @@ class TestDispatcher:
|
|||
"aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
|
||||
) as patched_listen_updates:
|
||||
patched_listen_updates.return_value = _mock_updates()
|
||||
await dispatcher._run_polling(bot)
|
||||
await dispatcher.start_polling(bot)
|
||||
|
||||
mocked_emit_startup.assert_awaited()
|
||||
mocked_process_update.assert_awaited()
|
||||
mocked_emit_shutdown.assert_awaited()
|
||||
|
||||
def test_run(self, bot: MockedBot):
|
||||
def test_run_polling(self, bot: MockedBot):
|
||||
dispatcher = Dispatcher()
|
||||
with patch("aiogram.dispatcher.dispatcher.Dispatcher._run_polling") as patched_run_polling:
|
||||
with patch("aiogram.dispatcher.dispatcher.Dispatcher.start_polling") as patched_start_polling:
|
||||
dispatcher.run_polling(bot)
|
||||
patched_run_polling.assert_awaited_once()
|
||||
patched_start_polling.assert_awaited_once()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue