Add tests for DataMixin

This commit is contained in:
jrootjunior 2019-11-15 14:09:37 +02:00
parent 013ee3d496
commit a6573656d0
5 changed files with 39 additions and 17 deletions

View file

@ -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"

View file

@ -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)

View file

@ -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

0
tests/utils/__init__.py Normal file
View file

View file

@ -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