From a6573656d0f62c30766fc49b36229b43ec659cb9 Mon Sep 17 00:00:00 2001 From: jrootjunior Date: Fri, 15 Nov 2019 14:09:37 +0200 Subject: [PATCH] Add tests for DataMixin --- aiogram/__init__.py | 7 ------- aiogram/utils/mixins.py | 3 +++ tests/test_nothing.py | 10 ---------- tests/utils/__init__.py | 0 tests/utils/test_mixins.py | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 17 deletions(-) delete mode 100644 tests/test_nothing.py create mode 100644 tests/utils/__init__.py create mode 100644 tests/utils/test_mixins.py diff --git a/aiogram/__init__.py b/aiogram/__init__.py index eb1f92ad..cc8c9a9b 100644 --- a/aiogram/__init__.py +++ b/aiogram/__init__.py @@ -1,13 +1,6 @@ from .api import methods, session, types from .api.client.bot import Bot -try: - import uvloop - - uvloop.install() -except ImportError: - uvloop = None - __all__ = ["__api_version__", "__version__", "types", "methods", "Bot", "session"] __version__ = "3.0dev.1" diff --git a/aiogram/utils/mixins.py b/aiogram/utils/mixins.py index de7e9cd0..12d22737 100644 --- a/aiogram/utils/mixins.py +++ b/aiogram/utils/mixins.py @@ -22,6 +22,9 @@ class DataMixin: def __delitem__(self, key): del self.data[key] + def __contains__(self, item): + return item in self.data + def get(self, key, default=None): return self.data.get(key, default) diff --git a/tests/test_nothing.py b/tests/test_nothing.py deleted file mode 100644 index 14684bdf..00000000 --- a/tests/test_nothing.py +++ /dev/null @@ -1,10 +0,0 @@ -import asyncio - -import pytest - - -class TestNothing: - @pytest.mark.asyncio - async def test_nothing(self): - result = await asyncio.sleep(1, result=42) - assert result == 42 diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/utils/test_mixins.py b/tests/utils/test_mixins.py new file mode 100644 index 00000000..c2141127 --- /dev/null +++ b/tests/utils/test_mixins.py @@ -0,0 +1,36 @@ +from aiogram.utils.mixins import DataMixin + + +class MyClass(DataMixin): + pass + + +class TestDataMixin: + def test_store_value(self): + obj = MyClass() + obj["foo"] = 42 + + assert "foo" in obj + assert obj["foo"] == 42 + assert len(obj.data) == 1 + + def test_remove_value(self): + obj = MyClass() + obj["foo"] = 42 + del obj["foo"] + + assert "key" not in obj + assert len(obj.data) == 0 + + def test_getter(self): + obj = MyClass() + obj["foo"] = 42 + + assert obj.get("foo") == 42 + assert obj.get("bar") is None + assert obj.get("baz", "test") == "test" + + +class TestContextInstanceMixin: + def test_instance(self): + pass