aiogram/tests/test_utils/test_mixins.py

24 lines
599 B
Python
Raw Normal View History

import pytest
2020-03-18 17:04:11 +03:00
from aiogram.utils.mixins import ContextInstanceMixin
2020-03-18 17:04:11 +03:00
class ContextObject(ContextInstanceMixin['ContextObject']):
pass
class TestContextInstanceMixin:
def test_empty(self):
obj = ContextObject()
assert obj.get_current(no_error=True) is None
with pytest.raises(LookupError):
assert obj.get_current(no_error=False)
def test_set_wrong_type(self):
obj = ContextObject()
with pytest.raises(
TypeError, match=r"Value should be instance of 'ContextObject' not '.+'"
):
obj.set_current(42)