"""Test helper methods.""" import asyncio import copy from typing import Any, Self class WithAsyncIterator: """Async Iterator test class. Borrowed from: https://github.com/Martiusweb/asynctest/blob/master/test/test_mock.py """ def __init__(self, items: Any): """Init the iterator and copy the input.""" self.items = copy.copy(items) def __aiter__(self) -> Self: """Return an iterator.""" return self async def __anext__(self) -> Any: """Return entries from items, then raises an iteration error.""" try: return self.items.pop(0) except IndexError: pass raise StopAsyncIteration def awaitable_return_value(return_value: Any) -> asyncio.Future[Any]: """Create an awaitable return value for the mock client.""" future: asyncio.Future[Any] = asyncio.Future() future.set_result(return_value) return future