mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Fixed coverage
This commit is contained in:
parent
bfa8971b1d
commit
b41eb34b17
6 changed files with 50 additions and 26 deletions
|
|
@ -77,6 +77,12 @@ class TestDispatcher:
|
|||
assert dp.update.handlers[0].callback == dp._listen_update
|
||||
assert dp.update.outer_middleware
|
||||
|
||||
def test_init_args(self, bot: MockedBot):
|
||||
with pytest.raises(TypeError):
|
||||
Dispatcher(bot)
|
||||
with pytest.raises(TypeError):
|
||||
Dispatcher(storage=bot)
|
||||
|
||||
def test_data_bind(self):
|
||||
dp = Dispatcher()
|
||||
assert dp.get("foo") is None
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ import functools
|
|||
from typing import Any, Dict, Union
|
||||
|
||||
import pytest
|
||||
from magic_filter import F as A
|
||||
|
||||
from aiogram import F
|
||||
from aiogram.dispatcher.event.handler import CallableMixin, FilterObject, HandlerObject
|
||||
from aiogram.filters import Filter
|
||||
from aiogram.handlers import BaseHandler
|
||||
from aiogram.types import Update
|
||||
from aiogram.utils.warnings import Recommendation
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
|
@ -209,3 +211,7 @@ class TestHandlerObject:
|
|||
assert len(handler.filters) == 1
|
||||
result = await handler.call(Update(update_id=42))
|
||||
assert result == 42
|
||||
|
||||
def test_warn_another_magic(self):
|
||||
with pytest.warns(Recommendation):
|
||||
FilterObject(callback=A.test.is_(True))
|
||||
|
|
|
|||
|
|
@ -6,13 +6,30 @@ import pytest
|
|||
from aiogram import F
|
||||
from aiogram.filters import Command, CommandObject
|
||||
from aiogram.filters.command import CommandStart
|
||||
from aiogram.types import Chat, Message, User
|
||||
from aiogram.types import BotCommand, Chat, Message, User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestCommandFilter:
|
||||
def test_commands_not_iterable(self):
|
||||
with pytest.raises(ValueError):
|
||||
Command(commands=1)
|
||||
|
||||
def test_bad_type(self):
|
||||
with pytest.raises(ValueError):
|
||||
Command(1)
|
||||
|
||||
def test_without_args(self):
|
||||
with pytest.raises(ValueError):
|
||||
Command()
|
||||
|
||||
def test_resolve_bot_command(self):
|
||||
command = Command(BotCommand(command="test", description="Test"))
|
||||
assert isinstance(command.commands[0], str)
|
||||
assert command.commands[0] == "test"
|
||||
|
||||
def test_convert_to_list(self):
|
||||
cmd = Command(commands="start")
|
||||
assert cmd.commands
|
||||
|
|
@ -86,6 +103,7 @@ class TestCommandFilter:
|
|||
),
|
||||
True,
|
||||
],
|
||||
[None, False],
|
||||
],
|
||||
)
|
||||
async def test_call(self, message: Message, result: bool, bot: MockedBot):
|
||||
|
|
@ -121,6 +139,19 @@ class TestCommandFilter:
|
|||
command_obj: CommandObject = result["command"]
|
||||
assert command_obj.mention is None
|
||||
|
||||
def test_str(self):
|
||||
cmd = Command(commands=["start"])
|
||||
assert str(cmd) == "Command('start', prefix='/', ignore_case=False, ignore_mention=False)"
|
||||
|
||||
|
||||
class TestCommandStart:
|
||||
def test_str(self):
|
||||
cmd = CommandStart()
|
||||
assert (
|
||||
str(cmd)
|
||||
== "CommandStart(ignore_case=False, ignore_mention=False, deep_link=False, deep_link_encoded=False)"
|
||||
)
|
||||
|
||||
|
||||
class TestCommandObject:
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -168,7 +199,3 @@ class TestCommandObject:
|
|||
|
||||
cmd.update_handler_flags(flags)
|
||||
assert len(flags["commands"]) == 2
|
||||
|
||||
def test_str(self):
|
||||
cmd = Command(commands=["start"])
|
||||
assert str(cmd) == "Command('start', prefix='/', ignore_case=False, ignore_mention=False)"
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ class TestExceptionTypeFilter:
|
|||
|
||||
assert result == value
|
||||
|
||||
def test_without_arguments(self):
|
||||
with pytest.raises(ValueError):
|
||||
ExceptionTypeFilter()
|
||||
|
||||
|
||||
class TestDispatchException:
|
||||
async def test_handle_exception(self, bot):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue