Make Dispatcher._run_polling public

This commit is contained in:
Alex Root Junior 2019-12-26 00:00:53 +02:00
parent 1d2c6c91d0
commit a2cb637ed9
3 changed files with 8 additions and 8 deletions

View file

@ -1,6 +1,6 @@
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
base_python := python3.7 base_python := python3
py := poetry run py := poetry run
python := $(py) python python := $(py) python

View file

@ -151,7 +151,7 @@ class Dispatcher(Router):
async for update in self._listen_updates(bot): async for update in self._listen_updates(bot):
await self.process_update(update=update, bot=bot, **kwargs) 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 Polling runner
@ -188,7 +188,7 @@ class Dispatcher(Router):
:return: :return:
""" """
try: try:
return asyncio.run(self._run_polling(*bots, **kwargs)) return asyncio.run(self.start_polling(*bots, **kwargs))
except (KeyboardInterrupt, SystemExit): # pragma: no cover except (KeyboardInterrupt, SystemExit): # pragma: no cover
# Allow to graceful shutdown # Allow to graceful shutdown
pass pass

View file

@ -164,7 +164,7 @@ class TestDispatcher:
mocked_process_update.assert_awaited() mocked_process_update.assert_awaited()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_run_polling(self, bot: MockedBot): async def test_start_polling(self, bot: MockedBot):
dispatcher = Dispatcher() dispatcher = Dispatcher()
bot.add_result_for( bot.add_result_for(
GetMe, ok=True, result=User(id=42, is_bot=True, first_name="The bot", username="tbot") 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" "aiogram.dispatcher.dispatcher.Dispatcher._listen_updates"
) as patched_listen_updates: ) as patched_listen_updates:
patched_listen_updates.return_value = _mock_updates() patched_listen_updates.return_value = _mock_updates()
await dispatcher._run_polling(bot) await dispatcher.start_polling(bot)
mocked_emit_startup.assert_awaited() mocked_emit_startup.assert_awaited()
mocked_process_update.assert_awaited() mocked_process_update.assert_awaited()
mocked_emit_shutdown.assert_awaited() mocked_emit_shutdown.assert_awaited()
def test_run(self, bot: MockedBot): def test_run_polling(self, bot: MockedBot):
dispatcher = Dispatcher() 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) dispatcher.run_polling(bot)
patched_run_polling.assert_awaited_once() patched_start_polling.assert_awaited_once()