fix linter, fix ci, fix tests
This commit is contained in:
@@ -6,15 +6,15 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from aiogram import types
|
||||
|
||||
from helper_bot.handlers.group.decorators import error_handler as group_error_handler
|
||||
from helper_bot.handlers.private.decorators import (
|
||||
error_handler as private_error_handler,
|
||||
)
|
||||
from helper_bot.handlers.group.decorators import \
|
||||
error_handler as group_error_handler
|
||||
from helper_bot.handlers.private.decorators import \
|
||||
error_handler as private_error_handler
|
||||
|
||||
|
||||
class FakeMessage:
|
||||
"""Класс-маркер, чтобы мок проходил isinstance(..., types.Message) в декораторе."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ class TestGroupErrorHandler:
|
||||
|
||||
async def test_success_returns_result(self):
|
||||
"""При успешном выполнении возвращается результат функции."""
|
||||
|
||||
@group_error_handler
|
||||
async def sample_handler():
|
||||
return "ok"
|
||||
@@ -34,6 +35,7 @@ class TestGroupErrorHandler:
|
||||
|
||||
async def test_exception_is_reraised(self):
|
||||
"""При исключении оно пробрасывается дальше."""
|
||||
|
||||
@group_error_handler
|
||||
async def failing_handler():
|
||||
raise ValueError("test error")
|
||||
@@ -44,6 +46,7 @@ class TestGroupErrorHandler:
|
||||
@patch("helper_bot.handlers.group.decorators.logger")
|
||||
async def test_exception_is_logged(self, mock_logger):
|
||||
"""При исключении вызывается logger.error."""
|
||||
|
||||
@group_error_handler
|
||||
async def failing_handler():
|
||||
raise RuntimeError("logged error")
|
||||
@@ -95,6 +98,7 @@ class TestPrivateErrorHandler:
|
||||
|
||||
async def test_success_returns_result(self):
|
||||
"""При успешном выполнении возвращается результат функции."""
|
||||
|
||||
@private_error_handler
|
||||
async def sample_handler():
|
||||
return 42
|
||||
@@ -104,6 +108,7 @@ class TestPrivateErrorHandler:
|
||||
|
||||
async def test_exception_is_reraised(self):
|
||||
"""При исключении оно пробрасывается дальше."""
|
||||
|
||||
@private_error_handler
|
||||
async def failing_handler():
|
||||
raise TypeError("private error")
|
||||
@@ -114,6 +119,7 @@ class TestPrivateErrorHandler:
|
||||
@patch("helper_bot.handlers.private.decorators.logger")
|
||||
async def test_exception_is_logged(self, mock_logger):
|
||||
"""При исключении вызывается logger.error."""
|
||||
|
||||
@private_error_handler
|
||||
async def failing_handler():
|
||||
raise KeyError("key missing")
|
||||
@@ -155,6 +161,7 @@ class TestPrivateErrorHandler:
|
||||
|
||||
async def test_no_message_in_args_no_send(self):
|
||||
"""Если в args нет Message, send_message не вызывается (только логирование)."""
|
||||
|
||||
@private_error_handler
|
||||
async def failing_handler():
|
||||
raise ValueError("no message")
|
||||
|
||||
Reference in New Issue
Block a user