Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated usage of coroutine. #69

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["pypy3.9", "pypy3.10", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
26 changes: 19 additions & 7 deletions test/test_memoize_decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from asyncio import (
coroutine, ensure_future, Event, gather, get_event_loop, new_event_loop, set_event_loop
ensure_future, Event, gather, get_event_loop, new_event_loop, set_event_loop
)
from atools import memoize
import atools._memoize_decorator as test_module
Expand Down Expand Up @@ -437,9 +437,15 @@ async def foo() -> None:
@pytest.mark.asyncio
async def test_async_locks_async(async_lock: MagicMock) -> None:
async_lock_context = async_lock.return_value = MagicMock()
type(async_lock_context).__aenter__ = \
coroutine(lambda *args, **kwargs: async_lock_context)
type(async_lock_context).__aexit__ = coroutine(lambda *args, **kwargs: None)

async def __aenter__(*args, **kwargs):
return async_lock_context

async def __aexit__(*args, **kwargs):
...

type(async_lock_context).__aenter__ = __aenter__
type(async_lock_context).__aexit__ = __aexit__

@memoize
async def foo() -> None:
Expand All @@ -451,9 +457,15 @@ async def foo() -> None:

def test_sync_does_not_async_lock(async_lock: MagicMock) -> None:
async_lock_context = async_lock.return_value = MagicMock()
type(async_lock_context).__aenter__ = \
coroutine(lambda *args, **kwargs: async_lock_context)
type(async_lock_context).__aexit__ = coroutine(lambda *args, **kwargs: None)

async def __aenter__(*args, **kwargs):
return async_lock_context

async def __aexit__(*args, **kwargs):
...

type(async_lock_context).__aenter__ = __aenter__
type(async_lock_context).__aexit__ = __aexit__

@memoize
def foo() -> None:
Expand Down
10 changes: 6 additions & 4 deletions test/test_rate_decorator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
from asyncio import coroutine, Event as AsyncEvent, gather
from asyncio import Event as AsyncEvent, gather
from atools import rate
from concurrent.futures import ThreadPoolExecutor
import pytest
Expand Down Expand Up @@ -97,12 +97,14 @@ def foo():
async def test_duration_causes_async_waiter_to_sleep(
async_sleep: MagicMock, time: MagicMock
) -> None:
async_sleep.side_effect = coroutine(lambda *_: None)
async def foo(*_):
...
async_sleep.side_effect = foo

@rate(size=1, duration=10)
async def foo():
async def bar():
...

await gather(foo(), foo())
await gather(bar(), bar())

async_sleep.assert_called_once_with(10)