2019-11-15 23:36:08 +02:00
|
|
|
import pytest
|
2019-11-16 00:52:18 +02:00
|
|
|
|
2020-03-18 17:04:11 +03:00
|
|
|
from aiogram.utils.mixins import ContextInstanceMixin
|
2019-11-15 23:36:08 +02:00
|
|
|
|
2020-03-18 17:04:11 +03:00
|
|
|
class ContextObject(ContextInstanceMixin['ContextObject']):
|
2019-11-15 23:36:08 +02:00
|
|
|
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()
|
|
|
|
|
|
2019-11-16 00:52:18 +02:00
|
|
|
with pytest.raises(
|
|
|
|
|
TypeError, match=r"Value should be instance of 'ContextObject' not '.+'"
|
|
|
|
|
):
|
2019-11-15 23:36:08 +02:00
|
|
|
obj.set_current(42)
|