mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Merge branch 'dev-3.x' into scenes
This commit is contained in:
commit
9514e60b98
7 changed files with 84 additions and 25 deletions
|
|
@ -53,7 +53,7 @@ class TestRedisEventIsolation:
|
|||
assert isolation.redis is not None
|
||||
assert isolation.key_builder is not None
|
||||
|
||||
assert pool.called_once_with("redis://localhost:6379/0")
|
||||
pool.assert_called_once_with("redis://localhost:6379/0")
|
||||
|
||||
async def test_close(self):
|
||||
isolation = RedisEventIsolation(redis=AsyncMock())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
import pytest
|
||||
import sys
|
||||
|
||||
from aiogram.fsm.state import State, StatesGroup, any_state
|
||||
|
||||
PY312_OR_GREATER = sys.version_info >= (3, 12)
|
||||
|
||||
|
||||
class TestState:
|
||||
def test_empty(self):
|
||||
|
|
@ -72,10 +75,20 @@ class TestState:
|
|||
assert state(None, check) is result
|
||||
|
||||
def test_state_in_unknown_class(self):
|
||||
with pytest.raises(RuntimeError):
|
||||
if PY312_OR_GREATER:
|
||||
# Python 3.12+ does not wrap __set_name__ exceptions with RuntimeError anymore as part
|
||||
# of PEP 678. See "Other Language Changes" in the changelogs:
|
||||
# https://docs.python.org/3/whatsnew/3.12.html
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
class MyClass:
|
||||
state1 = State()
|
||||
class MyClass:
|
||||
state1 = State()
|
||||
|
||||
else:
|
||||
with pytest.raises(RuntimeError):
|
||||
|
||||
class MyClass:
|
||||
state1 = State()
|
||||
|
||||
|
||||
class TestStatesGroup:
|
||||
|
|
|
|||
|
|
@ -181,10 +181,20 @@ class TestSimpleRequestHandler:
|
|||
"aiogram.dispatcher.dispatcher.Dispatcher.silent_call_request",
|
||||
new_callable=AsyncMock,
|
||||
) as mocked_silent_call_request:
|
||||
method_called_event = asyncio.Event()
|
||||
mocked_silent_call_request.side_effect = (
|
||||
lambda *args, **kwargs: method_called_event.set()
|
||||
)
|
||||
|
||||
handler_event.clear()
|
||||
resp = await self.make_reqest(client=client)
|
||||
assert resp.status == 200
|
||||
await asyncio.wait_for(handler_event.wait(), timeout=1)
|
||||
await asyncio.wait_for(method_called_event.wait(), timeout=1)
|
||||
# Python 3.12 had some changes to asyncio which make it quite a bit faster. But
|
||||
# probably because of that the assert_awaited call is consistently scheduled before the
|
||||
# silent_call_request call - failing the test. So we wait for the method to be called
|
||||
# before asserting if it has been awaited.
|
||||
mocked_silent_call_request.assert_awaited()
|
||||
result = await resp.json()
|
||||
assert not result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue