Skip to content

Commit

Permalink
make 3.7 work
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterseth committed Nov 26, 2022
1 parent 68c63fa commit 5358c1e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,26 @@
import pytest


# stub for python 3.7 support
class AsyncMock(mock.MagicMock):
def __init__(self, *args, **kwargs):
super(AsyncMock, self).__init__(*args, **kwargs)
self.__bool__ = lambda x: True
async def __call__(self, *args, **kwargs):
return super(AsyncMock, self).__call__(*args, **kwargs)


async def sleep_task(*args):
await asyncio.sleep(10)


@pytest.mark.asyncio
async def test_cancel_callback_called():
cancel_callback = mock.AsyncMock()
# can replace with mock.AsyncMock after python 3.7 support is dropped
cancel_callback = AsyncMock()
with pytest.raises(asyncio.TimeoutError):
# timeout raises asyncio.CancelledError, and await_many_dispatch should
# call cancel_callback
async with async_timeout.timeout(0):
await await_many_dispatch([sleep_task], sleep_task, cancel_callback)
assert cancel_callback.called

0 comments on commit 5358c1e

Please sign in to comment.