mirror of
https://github.com/gentoo-mirror/guru.git
synced 2026-07-18 03:23:20 -04:00
dev-python/backoff: new package, add 2.2.1
Upstream is dead. I'll maintain here until dev-util/mock migrates to another library. https://github.com/litl/backoff/issues/211 Signed-off-by: Takuya Wakazono <pastalian46@gmail.com>
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
https://github.com/litl/backoff/pull/224
|
||||
Adapt test cases to pytest-asyncio 1.0 compatibility
|
||||
|
||||
- Remove deprecated event_loop fixture
|
||||
https://pytest-asyncio.readthedocs.io/en/stable/reference/changelog.html#removed
|
||||
- Drop *_without_event_loop tests
|
||||
These incompatible tests (*1) are no longer needed since the
|
||||
underlying code has already been removed (introduced in a460156,
|
||||
removed in 5d714ccd).
|
||||
|
||||
*1: asyncio.get_event_loop() now raises a RuntimeError in Python 3.14
|
||||
when no loop exists.
|
||||
https://docs.python.org/3.14/whatsnew/3.14.html#id7
|
||||
--- a/tests/test_backoff_async.py
|
||||
+++ b/tests/test_backoff_async.py
|
||||
@@ -665,7 +665,7 @@ async def exceptor():
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
-async def test_on_exception_coro_cancelling(event_loop):
|
||||
+async def test_on_exception_coro_cancelling():
|
||||
sleep_started_event = asyncio.Event()
|
||||
|
||||
@backoff.on_predicate(backoff.expo)
|
||||
@@ -679,59 +679,10 @@ async def coro():
|
||||
|
||||
return False
|
||||
|
||||
- task = event_loop.create_task(coro())
|
||||
+ task = asyncio.create_task(coro())
|
||||
|
||||
await sleep_started_event.wait()
|
||||
|
||||
task.cancel()
|
||||
|
||||
assert (await task)
|
||||
-
|
||||
-
|
||||
-def test_on_predicate_on_regular_function_without_event_loop(monkeypatch):
|
||||
- monkeypatch.setattr('time.sleep', lambda x: None)
|
||||
-
|
||||
- # Set default event loop to None.
|
||||
- loop = asyncio.get_event_loop()
|
||||
- asyncio.set_event_loop(None)
|
||||
-
|
||||
- try:
|
||||
- @backoff.on_predicate(backoff.expo)
|
||||
- def return_true(log, n):
|
||||
- val = (len(log) == n - 1)
|
||||
- log.append(val)
|
||||
- return val
|
||||
-
|
||||
- log = []
|
||||
- ret = return_true(log, 3)
|
||||
- assert ret is True
|
||||
- assert 3 == len(log)
|
||||
-
|
||||
- finally:
|
||||
- # Restore event loop.
|
||||
- asyncio.set_event_loop(loop)
|
||||
-
|
||||
-
|
||||
-def test_on_exception_on_regular_function_without_event_loop(monkeypatch):
|
||||
- monkeypatch.setattr('time.sleep', lambda x: None)
|
||||
-
|
||||
- # Set default event loop to None.
|
||||
- loop = asyncio.get_event_loop()
|
||||
- asyncio.set_event_loop(None)
|
||||
-
|
||||
- try:
|
||||
- @backoff.on_exception(backoff.expo, KeyError)
|
||||
- def keyerror_then_true(log, n):
|
||||
- if len(log) == n:
|
||||
- return True
|
||||
- e = KeyError()
|
||||
- log.append(e)
|
||||
- raise e
|
||||
-
|
||||
- log = []
|
||||
- assert keyerror_then_true(log, 3) is True
|
||||
- assert 3 == len(log)
|
||||
-
|
||||
- finally:
|
||||
- # Restore event loop.
|
||||
- asyncio.set_event_loop(loop)
|
||||
Reference in New Issue
Block a user