Skip to content

Commit fbd56d2

Browse files
committed
compatibility with aiohttp>=3.8
1 parent 610b12e commit fbd56d2

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
python_files = test_*
33
python_functions = test_*
44
python_classes = TestSuite*
5+
asyncio_mode=auto

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
"Operating System :: Microsoft",
3232
"Programming Language :: Python",
3333
"Programming Language :: Python :: 3",
34-
"Programming Language :: Python :: 3.5",
35-
"Programming Language :: Python :: 3.6",
3634
"Programming Language :: Python :: 3.7",
3735
"Programming Language :: Python :: 3.8",
3836
"Programming Language :: Python :: 3.9",
37+
"Programming Language :: Python :: 3.10",
3938
"Programming Language :: Python :: Implementation :: CPython",
4039
],
4140
long_description=open("README.md").read(),

tests/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ def application(handler, socket_path):
2222

2323

2424
@pytest.fixture
25-
async def session(aiohttp_client, application, loop) -> ClientSession:
25+
async def session(aiohttp_client, application, event_loop) -> ClientSession:
2626
return await aiohttp_client(application)
2727

2828

2929
@pytest.fixture
30-
async def client(session: ClientSession, socket_path, loop) -> WSRPCClient:
31-
return WSRPCClient(socket_path, session=session, loop=loop)
30+
async def client(
31+
session: ClientSession, socket_path, event_loop
32+
) -> WSRPCClient:
33+
return WSRPCClient(socket_path, session=session, loop=event_loop)

tests/test_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ async def emitter(socket: WSRPCBase):
55
await socket.emit({"Hello": "world"})
66

77

8-
async def test_emitter(client: WSRPCClient, handler, loop):
8+
async def test_emitter(client: WSRPCClient, handler, event_loop):
99
handler.add_route("emitter", emitter)
1010

1111
async with client:
12-
future = loop.create_future()
12+
future = event_loop.create_future()
1313

1414
client.add_event_listener(future.set_result)
1515

tests/test_route.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,21 @@ def foobar(self):
102102
assert "foobar" not in FooRoute.__no_proxy__
103103

104104

105-
def test_route__init__(loop):
105+
async def test_route__init__(event_loop):
106106
socket = Mock()
107-
socket._loop = object()
108-
109107
route = Route(socket)
110108

111109
assert route.socket is socket
112-
assert route.loop is socket._loop
110+
assert route.loop is event_loop
113111

114112
socket = object()
115113
route = Route(socket)
116114

117115
assert route.socket is socket
118-
assert route.loop is loop
116+
assert route.loop is event_loop
119117

120118

121-
def test_abc_inheritance(loop):
119+
def test_abc_inheritance(event_loop):
122120
class AbstractMixin(ABC):
123121
@abstractmethod
124122
def foo(self):

tests/test_rpc_route.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ async def test_call_when_params_none(
151151

152152

153153
async def test_broadcast(
154-
client: WSRPCClient, handler: WebSocketAsync, route: Route, loop
154+
client: WSRPCClient, handler: WebSocketAsync, route: Route, event_loop
155155
):
156156
async with client:
157-
future = loop.create_future()
157+
future = event_loop.create_future()
158158

159159
async def on_broadcast(_, result):
160160
nonlocal future
@@ -229,7 +229,7 @@ def get_data(self, _):
229229

230230
async def test_call_timeout(client: WSRPCClient, handler: WebSocketAsync):
231231
async def will_sleep_for(_, seconds):
232-
with timeout(0.5):
232+
async with timeout(0.5):
233233
await asyncio.sleep(seconds)
234234
return DATA_TO_RETURN
235235

wsrpc_aiohttp/websocket/route.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from abc import ABCMeta
44
from types import MappingProxyType
5-
from typing import Any, Callable, Mapping
5+
from typing import Any, Callable, Mapping, Optional
66

77
from . import decorators
88
from .abc import AbstractRoute, AbstractWebSocket
@@ -63,17 +63,16 @@ class RouteBase(AbstractRoute, metaclass=RouteMeta):
6363
def __init__(self, socket: AbstractWebSocket):
6464
super().__init__(socket)
6565
self.__socket = socket
66-
self.__loop = getattr(self.socket, "_loop") or asyncio.get_event_loop()
67-
68-
if self.__loop is None:
69-
self.__loop = asyncio.get_event_loop()
66+
self.__loop: Optional[asyncio.AbstractEventLoop] = None
7067

7168
@property
7269
def socket(self) -> AbstractWebSocket:
7370
return self.__socket
7471

7572
@property
7673
def loop(self) -> asyncio.AbstractEventLoop:
74+
if self.__loop is None:
75+
self.__loop = asyncio.get_running_loop()
7776
return self.__loop
7877

7978
def _onclose(self):

0 commit comments

Comments
 (0)