mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Add tests for DataMixin
This commit is contained in:
parent
013ee3d496
commit
a6573656d0
5 changed files with 39 additions and 17 deletions
|
|
@ -1,13 +1,6 @@
|
||||||
from .api import methods, session, types
|
from .api import methods, session, types
|
||||||
from .api.client.bot import Bot
|
from .api.client.bot import Bot
|
||||||
|
|
||||||
try:
|
|
||||||
import uvloop
|
|
||||||
|
|
||||||
uvloop.install()
|
|
||||||
except ImportError:
|
|
||||||
uvloop = None
|
|
||||||
|
|
||||||
__all__ = ["__api_version__", "__version__", "types", "methods", "Bot", "session"]
|
__all__ = ["__api_version__", "__version__", "types", "methods", "Bot", "session"]
|
||||||
|
|
||||||
__version__ = "3.0dev.1"
|
__version__ = "3.0dev.1"
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,9 @@ class DataMixin:
|
||||||
def __delitem__(self, key):
|
def __delitem__(self, key):
|
||||||
del self.data[key]
|
del self.data[key]
|
||||||
|
|
||||||
|
def __contains__(self, item):
|
||||||
|
return item in self.data
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
return self.data.get(key, default)
|
return self.data.get(key, default)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
0
tests/utils/__init__.py
Normal file
36
tests/utils/test_mixins.py
Normal file
36
tests/utils/test_mixins.py
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue