mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
fix(handlerObj): fix parameter-spec solving (#408)
This commit is contained in:
parent
4863675d28
commit
00cff4acf5
2 changed files with 67 additions and 1 deletions
66
tests/test_dispatcher/test_handler.py
Normal file
66
tests/test_dispatcher/test_handler.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import functools
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.dispatcher.handler import Handler, _check_spec, _get_spec
|
||||
|
||||
|
||||
def callback1(foo: int, bar: int, baz: int):
|
||||
return locals()
|
||||
|
||||
|
||||
async def callback2(foo: int, bar: int, baz: int):
|
||||
return locals()
|
||||
|
||||
|
||||
async def callback3(foo: int, **kwargs):
|
||||
return locals()
|
||||
|
||||
|
||||
class TestHandlerObj:
|
||||
def test_init_decorated(self):
|
||||
def decorator(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
@decorator
|
||||
def callback1(foo, bar, baz):
|
||||
pass
|
||||
|
||||
@decorator
|
||||
@decorator
|
||||
def callback2(foo, bar, baz):
|
||||
pass
|
||||
|
||||
obj1 = Handler.HandlerObj(callback1, _get_spec(callback1))
|
||||
obj2 = Handler.HandlerObj(callback2, _get_spec(callback2))
|
||||
|
||||
assert set(obj1.spec.args) == {"foo", "bar", "baz"}
|
||||
assert obj1.handler == callback1
|
||||
assert set(obj2.spec.args) == {"foo", "bar", "baz"}
|
||||
assert obj2.handler == callback2
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"callback,kwargs,result",
|
||||
[
|
||||
pytest.param(
|
||||
callback1, {"foo": 42, "spam": True, "baz": "fuz"}, {"foo": 42, "baz": "fuz"}
|
||||
),
|
||||
pytest.param(
|
||||
callback2,
|
||||
{"foo": 42, "spam": True, "baz": "fuz", "bar": "test"},
|
||||
{"foo": 42, "baz": "fuz", "bar": "test"},
|
||||
),
|
||||
pytest.param(
|
||||
callback3,
|
||||
{"foo": 42, "spam": True, "baz": "fuz", "bar": "test"},
|
||||
{"foo": 42, "spam": True, "baz": "fuz", "bar": "test"},
|
||||
),
|
||||
],
|
||||
)
|
||||
def test__check_spec(self, callback, kwargs, result):
|
||||
spec = _get_spec(callback)
|
||||
assert _check_spec(spec, kwargs) == result
|
||||
Loading…
Add table
Add a link
Reference in a new issue