From 4960cbc409db340273115a33a1da273f2eae0f06 Mon Sep 17 00:00:00 2001 From: Francis CLAIRICIA-ROSE-CLAIRE-JOSEPHINE Date: Sat, 23 Sep 2023 14:39:14 +0200 Subject: [PATCH] [FIX] Renamed AsyncioBackend to AsyncIOBackend --- pyproject.toml | 3 - src/easynetwork/api_async/backend/factory.py | 9 +- src/easynetwork_asyncio/__init__.py | 6 +- src/easynetwork_asyncio/backend.py | 4 +- .../test_backend/test_asyncio_backend.py | 130 +++++++++--------- .../test_backend/test_backend_factory.py | 12 +- .../test_async/test_server/test_tcp.py | 4 +- .../test_api/test_backend/test_backend.py | 4 +- .../test_asyncio_backend/test_backend.py | 74 +++++----- 9 files changed, 123 insertions(+), 123 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c4d468f2..96d958b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,9 +62,6 @@ sniffio = [ "sniffio>=1.3.0", ] -[project.entry-points."easynetwork.async.backends"] -asyncio = "easynetwork_asyncio:AsyncioBackend" - ############################ pdm configuration ############################ [tool.pdm.dev-dependencies] diff --git a/src/easynetwork/api_async/backend/factory.py b/src/easynetwork/api_async/backend/factory.py index 5130aa08..f14a3cb9 100644 --- a/src/easynetwork/api_async/backend/factory.py +++ b/src/easynetwork/api_async/backend/factory.py @@ -151,7 +151,7 @@ def __load_backend_cls_from_entry_point(name: str) -> type[AsyncBackend]: @staticmethod @functools.cache def __get_available_backends() -> MappingProxyType[str, EntryPoint]: - from importlib.metadata import entry_points as get_all_entry_points + from importlib.metadata import EntryPoint, entry_points as get_all_entry_points entry_points = get_all_entry_points(group=AsyncBackendFactory.GROUP_NAME) duplicate_counter: Counter[str] = Counter([ep.name for ep in entry_points]) @@ -161,6 +161,11 @@ def __get_available_backends() -> MappingProxyType[str, EntryPoint]: backends: dict[str, EntryPoint] = {ep.name: ep for ep in entry_points} - assert "asyncio" in backends, "SystemError: Missing 'asyncio' entry point." # nosec assert_used + if "asyncio" not in backends: + backends["asyncio"] = EntryPoint( + name="asyncio", + value="easynetwork_asyncio:AsyncIOBackend", + group=AsyncBackendFactory.GROUP_NAME, + ) return MappingProxyType(backends) diff --git a/src/easynetwork_asyncio/__init__.py b/src/easynetwork_asyncio/__init__.py index 361cc7bc..cbd4aa32 100644 --- a/src/easynetwork_asyncio/__init__.py +++ b/src/easynetwork_asyncio/__init__.py @@ -17,8 +17,6 @@ from __future__ import annotations -__all__ = ["AsyncioBackend"] # type: list[str] +__all__ = ["AsyncIOBackend"] # type: list[str] -__version__ = "1.0.0" - -from .backend import AsyncioBackend +from .backend import AsyncIOBackend diff --git a/src/easynetwork_asyncio/backend.py b/src/easynetwork_asyncio/backend.py index 20aa176f..f9b7f8f7 100644 --- a/src/easynetwork_asyncio/backend.py +++ b/src/easynetwork_asyncio/backend.py @@ -17,7 +17,7 @@ from __future__ import annotations -__all__ = ["AsyncioBackend"] +__all__ = ["AsyncIOBackend"] import asyncio import asyncio.base_events @@ -61,7 +61,7 @@ _T_co = TypeVar("_T_co", covariant=True) -class AsyncioBackend(AbstractAsyncBackend): +class AsyncIOBackend(AbstractAsyncBackend): __slots__ = ("__use_asyncio_transport",) def __init__(self, *, transport: bool = True) -> None: diff --git a/tests/functional_test/test_async/test_backend/test_asyncio_backend.py b/tests/functional_test/test_async/test_backend/test_asyncio_backend.py index 4422a1db..4e222bf1 100644 --- a/tests/functional_test/test_async/test_backend/test_asyncio_backend.py +++ b/tests/functional_test/test_async/test_backend/test_asyncio_backend.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any from easynetwork.api_async.backend.factory import AsyncBackendFactory -from easynetwork_asyncio.backend import AsyncioBackend +from easynetwork_asyncio.backend import AsyncIOBackend import pytest @@ -24,18 +24,18 @@ class TestAsyncioBackend: @pytest.fixture @staticmethod - def backend() -> AsyncioBackend: + def backend() -> AsyncIOBackend: backend = AsyncBackendFactory.new("asyncio") - assert isinstance(backend, AsyncioBackend) + assert isinstance(backend, AsyncIOBackend) return backend - async def test____use_asyncio_transport____True_by_default(self, backend: AsyncioBackend) -> None: + async def test____use_asyncio_transport____True_by_default(self, backend: AsyncIOBackend) -> None: assert backend.using_asyncio_transport() async def test____cancel_shielded_coro_yield____mute_cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: task: asyncio.Task[None] = event_loop.create_task(backend.cancel_shielded_coro_yield()) @@ -53,7 +53,7 @@ async def test____cancel_shielded_coro_yield____cancel_at_the_next_checkpoint( self, cancel_message: str | None, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: test_list: list[str] = [] @@ -86,7 +86,7 @@ async def coroutine() -> None: async def test____ignore_cancellation____always_continue_on_cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: task: asyncio.Task[int] = event_loop.create_task(backend.ignore_cancellation(asyncio.sleep(0.5, 42))) @@ -101,7 +101,7 @@ async def test____ignore_cancellation____always_continue_on_cancellation( async def test____ignore_cancellation____task_does_not_appear_in_registered_tasks( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> bool: task = asyncio.current_task() @@ -115,7 +115,7 @@ async def coroutine() -> bool: async def test____ignore_cancellation____coroutine_cancelled_itself( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def self_cancellation() -> None: task = asyncio.current_task() @@ -133,7 +133,7 @@ async def self_cancellation() -> None: @pytest.mark.xfail("sys.version_info < (3, 12)", reason="asyncio.Task.get_context() does not exist before Python 3.12") async def test____ignore_cancellation____share_same_context_with_host_task( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: await asyncio.sleep(0.1) @@ -147,14 +147,14 @@ async def coroutine() -> None: async def test____timeout____respected( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.timeout(1): assert await asyncio.sleep(0.5, 42) == 42 async def test____timeout____timeout_error( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: with pytest.raises(TimeoutError): async with backend.timeout(0.25): @@ -163,7 +163,7 @@ async def test____timeout____timeout_error( async def test____timeout____cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: async with backend.timeout(0.25): @@ -178,7 +178,7 @@ async def coroutine() -> None: async def test____timeout_at____respected( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.timeout_at(event_loop.time() + 1): assert await asyncio.sleep(0.5, 42) == 42 @@ -186,7 +186,7 @@ async def test____timeout_at____respected( async def test____timeout_at____timeout_error( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: with pytest.raises(TimeoutError): async with backend.timeout_at(event_loop.time() + 0.25): @@ -195,7 +195,7 @@ async def test____timeout_at____timeout_error( async def test____timeout_at____cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: async with backend.timeout_at(event_loop.time() + 0.25): @@ -209,7 +209,7 @@ async def coroutine() -> None: async def test____move_on_after____respected( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.move_on_after(1) as handle: assert await asyncio.sleep(0.5, 42) == 42 @@ -218,7 +218,7 @@ async def test____move_on_after____respected( async def test____move_on_after____timeout_error( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.move_on_after(0.25) as handle: await asyncio.sleep(0.5, 42) @@ -228,7 +228,7 @@ async def test____move_on_after____timeout_error( async def test____move_on_after____cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: async with backend.move_on_after(0.25): @@ -243,7 +243,7 @@ async def coroutine() -> None: async def test____move_on_at____respected( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.move_on_at(event_loop.time() + 1) as handle: assert await asyncio.sleep(0.5, 42) == 42 @@ -253,7 +253,7 @@ async def test____move_on_at____respected( async def test____move_on_at____timeout_error( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.move_on_at(event_loop.time() + 0.25) as handle: await asyncio.sleep(0.5, 42) @@ -263,7 +263,7 @@ async def test____move_on_at____timeout_error( async def test____move_on_at____cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: async with backend.move_on_at(event_loop.time() + 0.25): @@ -278,7 +278,7 @@ async def coroutine() -> None: async def test____sleep_forever____sleep_until_cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: sleep_task = event_loop.create_task(backend.sleep_forever()) @@ -289,7 +289,7 @@ async def test____sleep_forever____sleep_until_cancellation( async def test____spawn_task____run_coroutine_in_background( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: return await asyncio.sleep(0.5, value) @@ -302,7 +302,7 @@ async def coroutine(value: int) -> int: async def test____spawn_task____task_cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: return await asyncio.sleep(0.5, value) @@ -318,7 +318,7 @@ async def coroutine(value: int) -> int: async def test____spawn_task____exception( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: await asyncio.sleep(0.1) @@ -331,7 +331,7 @@ async def coroutine(value: int) -> int: async def test____spawn_task____with_context( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: str) -> None: cvar_for_test.set(value) @@ -345,7 +345,7 @@ async def coroutine(value: str) -> None: async def test____create_task_group____task_pool( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: return await asyncio.sleep(0.5, value) @@ -376,7 +376,7 @@ async def coroutine(value: int) -> int: async def test____create_task_group____task_cancellation( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: return await asyncio.sleep(0.5, value) @@ -405,7 +405,7 @@ async def coroutine(value: int) -> int: async def test____create_task_group____task_join_cancel_shielding( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: return await asyncio.sleep(0.5, value) @@ -425,7 +425,7 @@ async def coroutine(value: int) -> int: async def test____create_task_group____start_soon_with_context( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: str) -> None: cvar_for_test.set(value) @@ -441,7 +441,7 @@ async def coroutine(value: str) -> None: async def test____wait_future____wait_until_done( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() event_loop.call_later(0.5, future.set_result, 42) @@ -453,7 +453,7 @@ async def test____wait_future____cancel_future_if_task_is_cancelled( self, future_running: str | None, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() if future_running == "before": @@ -484,7 +484,7 @@ async def test____wait_future____cancel_future_if_task_is_cancelled( async def test____wait_future____future_is_cancelled( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() task = event_loop.create_task(backend.wait_future(future)) @@ -497,7 +497,7 @@ async def test____wait_future____future_is_cancelled( async def test____wait_future____already_done( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() future.set_result(42) @@ -506,7 +506,7 @@ async def test____wait_future____already_done( async def test____wait_future____already_cancelled( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() future.cancel() @@ -517,7 +517,7 @@ async def test____wait_future____already_cancelled( async def test____wait_future____already_cancelled____task_cancelled_too( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() future.cancel() @@ -531,7 +531,7 @@ async def test____wait_future____already_cancelled____task_cancelled_too( async def test____wait_future____task_cancellation_prevails_over_future_cancellation( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: future: Future[int] = Future() @@ -550,7 +550,7 @@ async def test____wait_future____task_cancellation_prevails_over_future_cancella async def test____run_in_thread____cannot_be_cancelled( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: task = event_loop.create_task(backend.run_in_thread(time.sleep, 0.5)) event_loop.call_later(0.1, task.cancel) @@ -563,7 +563,7 @@ async def test____run_in_thread____cannot_be_cancelled( assert not task.cancelled() @pytest.mark.feature_sniffio - async def test____run_in_thread____sniffio_contextvar_reset(self, backend: AsyncioBackend) -> None: + async def test____run_in_thread____sniffio_contextvar_reset(self, backend: AsyncIOBackend) -> None: import sniffio sniffio.current_async_library_cvar.set("asyncio") @@ -580,7 +580,7 @@ def callback() -> str | None: async def test____create_threads_portal____run_coroutine_from_thread( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: threads_portal = backend.create_threads_portal() @@ -608,7 +608,7 @@ def thread() -> int: async def test____create_threads_portal____run_coroutine_from_thread____can_be_called_from_other_event_loop( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: assert asyncio.get_running_loop() is event_loop @@ -626,7 +626,7 @@ async def main() -> int: async def test____create_threads_portal____run_coroutine_from_thread____exception_raised( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: expected_exception = OSError("Why not?") @@ -644,7 +644,7 @@ def thread() -> int: async def test____create_threads_portal____run_coroutine_from_thread____coroutine_cancelled( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: task = asyncio.current_task() @@ -662,7 +662,7 @@ def thread() -> int: async def test____create_threads_portal____run_coroutine_from_thread____explicit_concurrent_future_Cancelled( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine(value: int) -> int: raise FutureCancelledError() @@ -678,7 +678,7 @@ def thread() -> int: @pytest.mark.feature_sniffio async def test____create_threads_portal____run_coroutine_from_thread____sniffio_contextvar_reset( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: import sniffio @@ -700,7 +700,7 @@ def thread() -> str | None: async def test____create_threads_portal____run_sync_from_thread_in_event_loop( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: threads_portal = backend.create_threads_portal() @@ -728,7 +728,7 @@ def thread() -> int: async def test____create_threads_portal____run_sync_from_thread_in_event_loop____can_be_called_from_other_event_loop( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: def not_threadsafe_func(value: int) -> int: assert asyncio.get_running_loop() is event_loop @@ -746,7 +746,7 @@ async def main() -> int: async def test____create_threads_portal____run_sync_from_thread_in_event_loop____exception_raised( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: expected_exception = OSError("Why not?") @@ -764,7 +764,7 @@ def thread() -> int: async def test____create_threads_portal____run_sync_from_thread_in_event_loop____explicit_concurrent_future_Cancelled( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: def not_threadsafe_func(value: int) -> int: raise FutureCancelledError() @@ -779,7 +779,7 @@ def thread() -> int: async def test____create_threads_portal____run_sync_from_thread_in_event_loop____async_function_given( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def coroutine() -> None: raise AssertionError("Should not be called") @@ -796,7 +796,7 @@ def thread() -> None: @pytest.mark.feature_sniffio async def test____create_threads_portal____run_sync_from_thread_in_event_loop____sniffio_contextvar_reset( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: import sniffio @@ -818,7 +818,7 @@ def thread() -> str | None: async def test____create_threads_portal____run_sync_soon____future_cancelled_before_call( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: func_stub = mocker.stub() @@ -842,7 +842,7 @@ def thread() -> None: async def test____create_threads_portal____run_coroutine_soon____future_cancelled( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: def thread() -> None: future = threads_portal.run_coroutine_soon(asyncio.sleep, 1) @@ -861,7 +861,7 @@ def thread() -> None: async def test____create_threads_portal____run_coroutine_soon____future_cancelled____cancellation_ignored( self, value: int | Exception, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: cancellation_ignored = mocker.stub() @@ -895,7 +895,7 @@ def thread() -> None: async def test____create_threads_portal____context_exit____wait_scheduled_call_soon( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: func_stub = mocker.stub() @@ -916,7 +916,7 @@ def thread() -> None: async def test____create_threads_portal____context_exit____wait_scheduled_call_soon_for_coroutine( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: coro_stub: AsyncMock = mocker.async_stub() @@ -936,7 +936,7 @@ def thread() -> None: async def test____create_threads_portal____entered_twice( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async with backend.create_threads_portal() as threads_portal: with pytest.raises(RuntimeError, match=r"ThreadsPortal entered twice\."): @@ -947,16 +947,16 @@ async def test____create_threads_portal____entered_twice( class TestAsyncioBackendShieldedCancellation: @pytest.fixture @staticmethod - def backend() -> AsyncioBackend: + def backend() -> AsyncIOBackend: backend = AsyncBackendFactory.new("asyncio") - assert isinstance(backend, AsyncioBackend) + assert isinstance(backend, AsyncIOBackend) return backend @pytest.fixture(params=["cancel_shielded_coro_yield", "ignore_cancellation", "run_in_thread", "wait_future"]) @staticmethod def cancel_shielded_coroutine( request: pytest.FixtureRequest, - backend: AsyncioBackend, + backend: AsyncIOBackend, event_loop: asyncio.AbstractEventLoop, ) -> Callable[[], Awaitable[Any]]: match getattr(request, "param"): @@ -982,7 +982,7 @@ async def test____cancel_shielded_coroutine____do_not_cancel_at_timeout_end( self, cancel_shielded_coroutine: Callable[[], Awaitable[Any]], event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: checkpoints: list[str] = [] @@ -1005,7 +1005,7 @@ async def test____cancel_shielded_coroutine____cancel_at_timeout_end_if_nested( self, cancel_shielded_coroutine: Callable[[], Awaitable[Any]], event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: checkpoints: list[str] = [] @@ -1045,7 +1045,7 @@ async def test____timeout____cancel_at_timeout_end_if_task_cancellation_were_alr self, cancel_shielded_coroutine: Callable[[], Awaitable[Any]], event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: checkpoints: list[str] = [] @@ -1076,7 +1076,7 @@ async def coroutine(value: int) -> int: async def test____ignore_cancellation____do_not_reschedule_if_inner_task_cancelled_itself( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: async def self_cancellation() -> None: task = asyncio.current_task() diff --git a/tests/functional_test/test_async/test_backend/test_backend_factory.py b/tests/functional_test/test_async/test_backend/test_backend_factory.py index d0c89a95..f5853650 100644 --- a/tests/functional_test/test_async/test_backend/test_backend_factory.py +++ b/tests/functional_test/test_async/test_backend/test_backend_factory.py @@ -19,18 +19,18 @@ def test____get_available_backends____imports_asyncio_backend(self) -> None: assert AsyncBackendFactory.get_available_backends() == frozenset({"asyncio"}) def test____get_all_backends____imports_asyncio_backend(self) -> None: - from easynetwork_asyncio import AsyncioBackend + from easynetwork_asyncio import AsyncIOBackend - assert AsyncBackendFactory.get_all_backends() == {"asyncio": AsyncioBackend} + assert AsyncBackendFactory.get_all_backends() == {"asyncio": AsyncIOBackend} def test____get_default_backend____returns_asyncio_backend(self) -> None: - from easynetwork_asyncio import AsyncioBackend + from easynetwork_asyncio import AsyncIOBackend - assert AsyncBackendFactory.get_default_backend(guess_current_async_library=False) is AsyncioBackend + assert AsyncBackendFactory.get_default_backend(guess_current_async_library=False) is AsyncIOBackend def test____new____returns_asyncio_backend_instance(self) -> None: - from easynetwork_asyncio import AsyncioBackend + from easynetwork_asyncio import AsyncIOBackend backend = AsyncBackendFactory.new("asyncio") - assert isinstance(backend, AsyncioBackend) + assert isinstance(backend, AsyncIOBackend) diff --git a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py index 11b01b33..29f46a23 100644 --- a/tests/functional_test/test_communication/test_async/test_server/test_tcp.py +++ b/tests/functional_test/test_communication/test_async/test_server/test_tcp.py @@ -23,7 +23,7 @@ from easynetwork.protocol import StreamProtocol from easynetwork.tools.socket import SocketAddress, enable_socket_linger from easynetwork_asyncio._utils import create_connection -from easynetwork_asyncio.backend import AsyncioBackend +from easynetwork_asyncio.backend import AsyncIOBackend from easynetwork_asyncio.stream.listener import ListenerSocketAdapter import pytest @@ -32,7 +32,7 @@ from .base import BaseTestAsyncServer -class NoListenerErrorBackend(AsyncioBackend): +class NoListenerErrorBackend(AsyncIOBackend): async def create_tcp_listeners( self, host: str | Sequence[str] | None, diff --git a/tests/unit_test/test_async/test_api/test_backend/test_backend.py b/tests/unit_test/test_async/test_api/test_backend/test_backend.py index dd2fc3df..bc5d4b67 100644 --- a/tests/unit_test/test_async/test_api/test_backend/test_backend.py +++ b/tests/unit_test/test_async/test_api/test_backend/test_backend.py @@ -102,9 +102,9 @@ def reset_factory_cache_at_end() -> Iterator[None]: yield AsyncBackendFactory.invalidate_backends_cache() - from easynetwork_asyncio import AsyncioBackend + from easynetwork_asyncio import AsyncIOBackend - assert AsyncBackendFactory.get_all_backends() == {"asyncio": AsyncioBackend} + assert AsyncBackendFactory.get_all_backends() == {"asyncio": AsyncIOBackend} @pytest.fixture(autouse=True) @staticmethod diff --git a/tests/unit_test/test_async/test_asyncio_backend/test_backend.py b/tests/unit_test/test_async/test_asyncio_backend/test_backend.py index 6a564409..2fc12836 100644 --- a/tests/unit_test/test_async/test_asyncio_backend/test_backend.py +++ b/tests/unit_test/test_async/test_asyncio_backend/test_backend.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any, cast from easynetwork.api_async.backend.abc import AsyncStreamSocketAdapter -from easynetwork_asyncio import AsyncioBackend +from easynetwork_asyncio import AsyncIOBackend import pytest @@ -23,14 +23,14 @@ class TestAsyncIOBackendSync: @pytest.fixture @staticmethod - def backend() -> AsyncioBackend: - return AsyncioBackend() + def backend() -> AsyncIOBackend: + return AsyncIOBackend() @pytest.mark.parametrize("runner_options", [{"loop_factory": 42}, None]) def test____bootstrap____start_new_runner( self, runner_options: dict[str, Any] | None, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -79,8 +79,8 @@ def use_asyncio_transport(request: Any) -> bool: @pytest.fixture @staticmethod - def backend(use_asyncio_transport: bool) -> AsyncioBackend: - return AsyncioBackend(transport=use_asyncio_transport) + def backend(use_asyncio_transport: bool) -> AsyncIOBackend: + return AsyncIOBackend(transport=use_asyncio_transport) @pytest.fixture(params=[("local_address", 12345), None], ids=lambda addr: f"local_address=={addr}") @staticmethod @@ -94,7 +94,7 @@ def remote_address(request: Any) -> tuple[str, int] | None: async def test____use_asyncio_transport____follows_option( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, ) -> None: assert backend.using_asyncio_transport() == use_asyncio_transport @@ -103,7 +103,7 @@ async def test____use_asyncio_transport____follows_option( async def test____coro_yield____use_asyncio_sleep( self, cancel_shielded: bool, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -120,7 +120,7 @@ async def test____coro_yield____use_asyncio_sleep( async def test____get_cancelled_exc_class____returns_asyncio_CancelledError( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: # Arrange @@ -130,7 +130,7 @@ async def test____get_cancelled_exc_class____returns_asyncio_CancelledError( async def test____current_time____use_event_loop_time( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -145,7 +145,7 @@ async def test____current_time____use_event_loop_time( async def test____sleep____use_asyncio_sleep( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -159,7 +159,7 @@ async def test____sleep____use_asyncio_sleep( async def test____ignore_cancellation____not_a_coroutine( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -178,7 +178,7 @@ async def test____create_tcp_connection____use_asyncio_open_connection( ssl: bool, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_asyncio_stream_reader_factory: Callable[[], MagicMock], mock_asyncio_stream_writer_factory: Callable[[], MagicMock], mock_ssl_context: MagicMock, @@ -241,7 +241,7 @@ async def test____create_tcp_connection____use_asyncio_open_connection____no_hap ssl: bool, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_asyncio_stream_reader_factory: Callable[[], MagicMock], mock_asyncio_stream_writer_factory: Callable[[], MagicMock], mock_ssl_context: MagicMock, @@ -296,7 +296,7 @@ async def test____create_tcp_connection____use_asyncio_open_connection____happy_ ssl: bool, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_asyncio_stream_reader_factory: Callable[[], MagicMock], mock_asyncio_stream_writer_factory: Callable[[], MagicMock], mock_ssl_context: MagicMock, @@ -351,7 +351,7 @@ async def test____create_tcp_connection____creates_raw_socket_adapter( event_loop: asyncio.AbstractEventLoop, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_tcp_socket: Callable[[], MagicMock], mocker: MockerFixture, ) -> None: @@ -391,7 +391,7 @@ async def test____create_tcp_connection____happy_eyeballs_delay_not_supported( self, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -427,7 +427,7 @@ async def test____create_ssl_over_tcp_connection____ssl_not_supported( self, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_ssl_context: MagicMock, mocker: MockerFixture, ) -> None: @@ -472,7 +472,7 @@ async def test____create_ssl_over_tcp_connection____invalid_ssl_context_value( self, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -507,7 +507,7 @@ async def test____create_ssl_over_tcp_connection____no_ssl_module( self, local_address: tuple[str, int] | None, remote_address: tuple[str, int], - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -539,7 +539,7 @@ async def test____create_ssl_over_tcp_connection____no_ssl_module( async def test____wrap_tcp_client_socket____use_asyncio_open_connection( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_tcp_socket: MagicMock, mock_asyncio_stream_reader_factory: Callable[[], MagicMock], @@ -580,7 +580,7 @@ async def test____wrap_tcp_client_socket____use_asyncio_open_connection( async def test____wrap_ssl_over_tcp_client_socket____use_asyncio_open_connection( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_tcp_socket: MagicMock, mock_asyncio_stream_reader_factory: Callable[[], MagicMock], @@ -636,7 +636,7 @@ async def test____wrap_ssl_over_tcp_client_socket____use_asyncio_open_connection async def test____wrap_ssl_over_tcp_client_socket____ssl_not_supported( self, mock_tcp_socket: MagicMock, - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_ssl_context: MagicMock, mocker: MockerFixture, ) -> None: @@ -678,7 +678,7 @@ async def test____wrap_ssl_over_tcp_client_socket____ssl_not_supported( async def test____wrap_ssl_over_tcp_client_socket____invalid_ssl_context_value( self, mock_tcp_socket: MagicMock, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -710,7 +710,7 @@ async def test____wrap_ssl_over_tcp_client_socket____invalid_ssl_context_value( async def test____wrap_ssl_over_tcp_client_socket____no_ssl_module( self, mock_tcp_socket: MagicMock, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -749,7 +749,7 @@ async def test____wrap_ssl_over_tcp_client_socket____no_ssl_module( async def test____create_tcp_listeners____open_listener_sockets( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_tcp_socket: MagicMock, use_ssl: bool, @@ -853,7 +853,7 @@ async def test____create_tcp_listeners____bind_to_any_interfaces( self, remote_host: str, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_tcp_socket: MagicMock, use_ssl: bool, @@ -965,7 +965,7 @@ async def test____create_tcp_listeners____bind_to_any_interfaces( async def test____create_tcp_listeners____bind_to_several_hosts( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_tcp_socket: MagicMock, use_ssl: bool, @@ -1081,7 +1081,7 @@ async def test____create_tcp_listeners____bind_to_several_hosts( async def test____create_tcp_listeners____error_getaddrinfo_returns_empty_list( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_ssl: bool, mock_ssl_context: MagicMock, mocker: MockerFixture, @@ -1145,7 +1145,7 @@ async def test____create_tcp_listeners____error_getaddrinfo_returns_empty_list( async def test____create_ssl_over_tcp_listeners____ssl_not_supported( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_ssl_context: MagicMock, mocker: MockerFixture, ) -> None: @@ -1193,7 +1193,7 @@ async def test____create_udp_endpoint____use_loop_create_datagram_endpoint( event_loop: asyncio.AbstractEventLoop, local_address: tuple[str, int] | None, remote_address: tuple[str, int] | None, - backend: AsyncioBackend, + backend: AsyncIOBackend, mock_datagram_endpoint_factory: Callable[[], MagicMock], use_asyncio_transport: bool, mock_udp_socket: MagicMock, @@ -1251,7 +1251,7 @@ async def test____create_udp_endpoint____use_loop_create_datagram_endpoint( async def test____wrap_udp_socket____use_loop_create_datagram_endpoint( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, use_asyncio_transport: bool, mock_udp_socket: MagicMock, mock_datagram_endpoint_factory: Callable[[], MagicMock], @@ -1291,7 +1291,7 @@ async def test____wrap_udp_socket____use_loop_create_datagram_endpoint( async def test____create_lock____use_asyncio_Lock_class( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -1306,7 +1306,7 @@ async def test____create_lock____use_asyncio_Lock_class( async def test____create_event____use_asyncio_Event_class( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -1323,7 +1323,7 @@ async def test____create_event____use_asyncio_Event_class( async def test____create_condition_var____use_asyncio_Condition_class( self, use_lock: type[asyncio.Lock] | None, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -1340,7 +1340,7 @@ async def test____create_condition_var____use_asyncio_Condition_class( async def test____run_in_thread____use_loop_run_in_executor( self, event_loop: asyncio.AbstractEventLoop, - backend: AsyncioBackend, + backend: AsyncIOBackend, mocker: MockerFixture, ) -> None: # Arrange @@ -1378,7 +1378,7 @@ async def test____run_in_thread____use_loop_run_in_executor( async def test____create_threads_portal____returns_asyncio_portal( self, - backend: AsyncioBackend, + backend: AsyncIOBackend, ) -> None: # Arrange from easynetwork_asyncio.threads import ThreadsPortal