From fa42dcdce2be6a9e3784a6f55921b417fc9988e2 Mon Sep 17 00:00:00 2001 From: jrootjunior Date: Tue, 26 Nov 2019 11:25:44 +0200 Subject: [PATCH] Cover base filter --- aiogram/dispatcher/filters/base.py | 3 +- .../test_dispatcher/test_filters/test_base.py | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/test_dispatcher/test_filters/test_base.py diff --git a/aiogram/dispatcher/filters/base.py b/aiogram/dispatcher/filters/base.py index ce7b007c..fabaaf21 100644 --- a/aiogram/dispatcher/filters/base.py +++ b/aiogram/dispatcher/filters/base.py @@ -17,5 +17,6 @@ class BaseFilter(ABC, BaseModel): async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]: pass - def __await__(self): + def __await__(self): # pragma: no cover + # Is needed only for inspection and this method is never be called return self.__call__ diff --git a/tests/test_dispatcher/test_filters/test_base.py b/tests/test_dispatcher/test_filters/test_base.py new file mode 100644 index 00000000..dd183fb5 --- /dev/null +++ b/tests/test_dispatcher/test_filters/test_base.py @@ -0,0 +1,30 @@ +from typing import Awaitable +from unittest.mock import patch + +import pytest +from asynctest import CoroutineMock + +from aiogram.dispatcher.filters.base import BaseFilter + + +class MyFilter(BaseFilter): + foo: str + + async def __call__(self, event: str): + return + + +class TestBaseFilter: + @pytest.mark.asyncio + async def test_awaitable(self): + my_filter = MyFilter(foo="bar") + + assert isinstance(my_filter, Awaitable) + + with patch( + "tests.test_dispatcher.test_filters.test_base.MyFilter.__call__", + new_callable=CoroutineMock, + ) as mocked_call: + call = my_filter(event="test") + await call + mocked_call.assert_awaited_with(event="test")