mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
Remove warnings about pytest asyncio mode
This commit is contained in:
parent
a0dbbcfd5d
commit
655b3a2d48
134 changed files with 30 additions and 517 deletions
|
|
@ -1,12 +1,8 @@
|
|||
from typing import Awaitable
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.filters import Filter
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class MyFilter(Filter):
|
||||
async def __call__(self, event: str):
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
from decimal import Decimal
|
||||
from enum import Enum, auto
|
||||
from fractions import Fraction
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
|
||||
import pytest
|
||||
from magic_filter import MagicFilter
|
||||
|
|
@ -12,8 +9,6 @@ from aiogram import F
|
|||
from aiogram.filters.callback_data import CallbackData
|
||||
from aiogram.types import CallbackQuery, User
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class MyIntEnum(Enum):
|
||||
FOO = auto()
|
||||
|
|
@ -50,35 +45,36 @@ class TestCallbackData:
|
|||
class MyInvalidCallback(CallbackData, prefix="sp@m", sep="@"):
|
||||
pass
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"value,success,expected",
|
||||
[
|
||||
[None, True, ""],
|
||||
[42, True, "42"],
|
||||
["test", True, "test"],
|
||||
[9.99, True, "9.99"],
|
||||
[Decimal("9.99"), True, "9.99"],
|
||||
[Fraction("3/2"), True, "3/2"],
|
||||
[
|
||||
UUID("123e4567-e89b-12d3-a456-426655440000"),
|
||||
True,
|
||||
"123e4567-e89b-12d3-a456-426655440000",
|
||||
],
|
||||
[MyIntEnum.FOO, True, "1"],
|
||||
[MyStringEnum.FOO, True, "FOO"],
|
||||
[..., False, "..."],
|
||||
[object, False, "..."],
|
||||
[object(), False, "..."],
|
||||
[User(id=42, is_bot=False, first_name="test"), False, "..."],
|
||||
],
|
||||
)
|
||||
def test_encode_value(self, value, success, expected):
|
||||
callback = MyCallback(foo="test", bar=42)
|
||||
if success:
|
||||
assert callback._encode_value("test", value) == expected
|
||||
else:
|
||||
with pytest.raises(ValueError):
|
||||
assert callback._encode_value("test", value) == expected
|
||||
#
|
||||
# @pytest.mark.parametrize(
|
||||
# "value,success,expected",
|
||||
# [
|
||||
# [None, True, ""],
|
||||
# [42, True, "42"],
|
||||
# ["test", True, "test"],
|
||||
# [9.99, True, "9.99"],
|
||||
# [Decimal("9.99"), True, "9.99"],
|
||||
# [Fraction("3/2"), True, "3/2"],
|
||||
# [
|
||||
# UUID("123e4567-e89b-12d3-a456-426655440000"),
|
||||
# True,
|
||||
# "123e4567-e89b-12d3-a456-426655440000",
|
||||
# ],
|
||||
# [MyIntEnum.FOO, True, "1"],
|
||||
# [MyStringEnum.FOO, True, "FOO"],
|
||||
# [..., False, "..."],
|
||||
# [object, False, "..."],
|
||||
# [object(), False, "..."],
|
||||
# [User(id=42, is_bot=False, first_name="test"), False, "..."],
|
||||
# ],
|
||||
# )
|
||||
# def test_encode_value(self, value, success, expected):
|
||||
# callback = MyCallback(foo="test", bar=42)
|
||||
# if success:
|
||||
# assert callback._encode_value("test", value) == expected
|
||||
# else:
|
||||
# with pytest.raises(ValueError):
|
||||
# assert callback._encode_value("test", value) == expected
|
||||
|
||||
def test_pack(self):
|
||||
with pytest.raises(ValueError, match="Separator symbol .+"):
|
||||
|
|
|
|||
|
|
@ -267,7 +267,6 @@ class TestMemberStatusTransition:
|
|||
|
||||
|
||||
class TestChatMemberUpdatedStatusFilter:
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"transition,old,new,result",
|
||||
[
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ from aiogram.filters.command import CommandStart
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ from aiogram.filters import ExceptionMessageFilter, ExceptionTypeFilter
|
|||
from aiogram.types import Update
|
||||
from aiogram.types.error_event import ErrorEvent
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestExceptionMessageFilter:
|
||||
@pytest.mark.parametrize("value", ["value", re.compile("value")])
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import pytest
|
||||
from magic_filter import AttrDict
|
||||
|
||||
from aiogram import F
|
||||
|
|
@ -7,7 +6,6 @@ from aiogram.types import Update
|
|||
|
||||
|
||||
class TestMagicDataFilter:
|
||||
@pytest.mark.asyncio
|
||||
async def test_call(self):
|
||||
called = False
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@ from aiogram.filters import StateFilter
|
|||
from aiogram.fsm.state import State, StatesGroup
|
||||
from aiogram.types import Update
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class MyGroup(StatesGroup):
|
||||
state = State()
|
||||
|
|
@ -40,7 +38,6 @@ class TestStateFilter:
|
|||
[[MyGroup, State("state")], "state", False],
|
||||
],
|
||||
)
|
||||
@pytestmark
|
||||
async def test_filter(self, state, current_state, result):
|
||||
f = StateFilter(*state)
|
||||
assert bool(await f(obj=Update(update_id=42), raw_state=current_state)) is result
|
||||
|
|
@ -49,11 +46,9 @@ class TestStateFilter:
|
|||
with pytest.raises(ValueError):
|
||||
StateFilter()
|
||||
|
||||
@pytestmark
|
||||
async def test_create_filter_from_state(self):
|
||||
FilterObject(callback=State(state="state"))
|
||||
|
||||
@pytestmark
|
||||
async def test_state_copy(self):
|
||||
class SG(StatesGroup):
|
||||
state = State()
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import pytest
|
|||
from aiogram.filters import Text
|
||||
from aiogram.types import CallbackQuery, Chat, InlineQuery, Message, Poll, PollOption, User
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
class TestText:
|
||||
@pytest.mark.parametrize(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue