mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Extended MagicFilter with aiogram-specific operation (#759)
* Extend MagicFilter with aiogram-specific operation * Added tests * Added changes annotation and update docs
This commit is contained in:
parent
092b3f06f2
commit
d7be55bc58
7 changed files with 85 additions and 11 deletions
21
tests/test_utils/test_magic_filter.py
Normal file
21
tests/test_utils/test_magic_filter.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from dataclasses import dataclass
|
||||
from re import Match
|
||||
|
||||
from aiogram import F
|
||||
from aiogram.utils.magic_filter import MagicFilter
|
||||
|
||||
|
||||
@dataclass
|
||||
class MyObject:
|
||||
text: str
|
||||
|
||||
|
||||
class TestMagicFilter:
|
||||
def test_operation_as(self):
|
||||
magic: MagicFilter = F.text.regexp(r"^(\d+)$").as_("match")
|
||||
|
||||
assert not magic.resolve(MyObject(text="test"))
|
||||
|
||||
result = magic.resolve(MyObject(text="123"))
|
||||
assert isinstance(result, dict)
|
||||
assert isinstance(result["match"], Match)
|
||||
Loading…
Add table
Add a link
Reference in a new issue