mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
This commit fixes the style issues introduced indd50a9baccording to the output from black, autopep8 and isort. Details:4e472085-2e87-4f61-b7a1-ed208506962f/
73 lines
2 KiB
Python
73 lines
2 KiB
Python
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))
|
|
|
|
if set(obj1.spec.args) != {"foo", "bar", "baz"}:
|
|
raise AssertionError
|
|
if obj1.handler != callback1:
|
|
raise AssertionError
|
|
if set(obj2.spec.args) != {"foo", "bar", "baz"}:
|
|
raise AssertionError
|
|
if obj2.handler != callback2:
|
|
raise AssertionError
|
|
|
|
@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)
|
|
if _check_spec(spec, kwargs) != result:
|
|
raise AssertionError
|