Copy async_lru for Python 3.7 compatibility
This commit is contained in:
parent
2b7188b1b8
commit
18c6ba62bb
15 changed files with 1321 additions and 0 deletions
39
tests/external/test_open.py
vendored
Normal file
39
tests/external/test_open.py
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import pytest
|
||||
from great_ai.external.async_lru import alru_cache
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
|
||||
async def test_alru_cache_open(check_lru, loop):
|
||||
@alru_cache()
|
||||
async def coro(val):
|
||||
return val
|
||||
|
||||
await coro(1)
|
||||
|
||||
check_lru(coro, hits=0, misses=1, cache=1, tasks=0)
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
coro.open()
|
||||
|
||||
close = coro.close()
|
||||
|
||||
assert coro.closed
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
await coro()
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
coro.open()
|
||||
|
||||
await close
|
||||
|
||||
check_lru(coro, hits=0, misses=0, cache=0, tasks=0)
|
||||
|
||||
coro.open()
|
||||
|
||||
ret = await coro(1)
|
||||
|
||||
assert ret == 1
|
||||
|
||||
check_lru(coro, hits=0, misses=1, cache=1, tasks=0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue