fix linter, fix ci, fix tests

This commit is contained in:
2026-02-02 00:46:44 +03:00
parent 68041037bd
commit d87d4e492e
93 changed files with 1042 additions and 862 deletions

View File

@@ -6,7 +6,6 @@ import asyncio
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from helper_bot.main import start_bot, start_bot_with_retry
@@ -15,11 +14,15 @@ from helper_bot.main import start_bot, start_bot_with_retry
class TestStartBotWithRetry:
"""Тесты для start_bot_with_retry."""
async def test_success_on_first_try_exits_immediately(self, mock_bot, mock_dispatcher):
async def test_success_on_first_try_exits_immediately(
self, mock_bot, mock_dispatcher
):
"""При успешном start_polling с первой попытки цикл завершается без повторов."""
mock_dispatcher.start_polling = AsyncMock()
await start_bot_with_retry(mock_bot, mock_dispatcher, max_retries=3)
mock_dispatcher.start_polling.assert_awaited_once_with(mock_bot, skip_updates=True)
mock_dispatcher.start_polling.assert_awaited_once_with(
mock_bot, skip_updates=True
)
@patch("helper_bot.main.asyncio.sleep", new_callable=AsyncMock)
async def test_network_error_retries_then_succeeds(
@@ -41,15 +44,15 @@ class TestStartBotWithRetry:
self, mock_bot, mock_dispatcher
):
"""При не-сетевой ошибке исключение пробрасывается без повторов."""
mock_dispatcher.start_polling = AsyncMock(
side_effect=ValueError("critical")
)
mock_dispatcher.start_polling = AsyncMock(side_effect=ValueError("critical"))
with pytest.raises(ValueError, match="critical"):
await start_bot_with_retry(mock_bot, mock_dispatcher, max_retries=3)
mock_dispatcher.start_polling.assert_awaited_once()
@patch("helper_bot.main.asyncio.sleep", new_callable=AsyncMock)
async def test_max_retries_exceeded_raises(self, mock_sleep, mock_bot, mock_dispatcher):
async def test_max_retries_exceeded_raises(
self, mock_sleep, mock_bot, mock_dispatcher
):
"""При исчерпании попыток из-за сетевых ошибок исключение пробрасывается."""
mock_dispatcher.start_polling = AsyncMock(
side_effect=ConnectionError("network error")