28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
import unittest
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import bot
|
|
|
|
|
|
class TypingStatusTests(unittest.IsolatedAsyncioTestCase):
|
|
async def test_sends_immediately_refreshes_and_cancels(self):
|
|
fake_bot = AsyncMock()
|
|
with patch.object(bot, "TYPING_REFRESH_SECONDS", 0.01):
|
|
async with bot.typing_status(fake_bot, 123):
|
|
await bot.asyncio.sleep(0.025)
|
|
self.assertGreaterEqual(fake_bot.send_chat_action.await_count, 2)
|
|
fake_bot.send_chat_action.assert_any_await(123, "typing")
|
|
|
|
async def test_stops_refresh_after_context(self):
|
|
fake_bot = AsyncMock()
|
|
with patch.object(bot, "TYPING_REFRESH_SECONDS", 0.01):
|
|
async with bot.typing_status(fake_bot, 123):
|
|
await bot.asyncio.sleep(0.015)
|
|
calls_after_exit = fake_bot.send_chat_action.await_count
|
|
await bot.asyncio.sleep(0.03)
|
|
self.assertEqual(fake_bot.send_chat_action.await_count, calls_after_exit)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|