fixes
This commit is contained in:
parent
b1682b286d
commit
01252e0b2c
|
@ -72,7 +72,7 @@ cdef class APIConnection:
|
|||
cdef public APIFrameHelper _frame_helper
|
||||
cdef public object api_version
|
||||
cdef public object connection_state
|
||||
cdef dict _message_handlers
|
||||
cdef public dict _message_handlers
|
||||
cdef public str log_name
|
||||
cdef set _read_exception_futures
|
||||
cdef object _ping_timer
|
||||
|
@ -81,7 +81,7 @@ cdef class APIConnection:
|
|||
cdef float _keep_alive_timeout
|
||||
cdef object _start_connect_task
|
||||
cdef object _finish_connect_task
|
||||
cdef object _fatal_exception
|
||||
cdef public Exception _fatal_exception
|
||||
cdef bint _expected_disconnect
|
||||
cdef object _loop
|
||||
cdef bint _send_pending_ping
|
||||
|
|
|
@ -940,15 +940,3 @@ class APIConnection:
|
|||
)
|
||||
|
||||
self._cleanup()
|
||||
|
||||
def _get_message_handlers(
|
||||
self,
|
||||
) -> dict[Any, set[Callable[[message.Message], None]]]:
|
||||
"""Get the message handlers.
|
||||
|
||||
This function is only used for testing for leaks.
|
||||
|
||||
It has to be bound to the real instance to work since
|
||||
_message_handlers is not a public attribute.
|
||||
"""
|
||||
return self._message_handlers
|
||||
|
|
|
@ -1246,9 +1246,7 @@ async def test_bluetooth_gatt_start_notify(
|
|||
client, connection, transport, protocol = api_client
|
||||
notifies = []
|
||||
|
||||
handlers_before = len(
|
||||
list(itertools.chain(*connection._get_message_handlers().values()))
|
||||
)
|
||||
handlers_before = len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
|
||||
def on_bluetooth_gatt_notify(handle: int, data: bytearray) -> None:
|
||||
notifies.append((handle, data))
|
||||
|
@ -1280,7 +1278,7 @@ async def test_bluetooth_gatt_start_notify(
|
|||
await cancel_cb()
|
||||
|
||||
assert (
|
||||
len(list(itertools.chain(*connection._get_message_handlers().values())))
|
||||
len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
== handlers_before
|
||||
)
|
||||
# Ensure abort callback is a no-op after cancel
|
||||
|
@ -1305,9 +1303,7 @@ async def test_bluetooth_gatt_start_notify_fails(
|
|||
def on_bluetooth_gatt_notify(handle: int, data: bytearray) -> None:
|
||||
notifies.append((handle, data))
|
||||
|
||||
handlers_before = len(
|
||||
list(itertools.chain(*connection._get_message_handlers().values()))
|
||||
)
|
||||
handlers_before = len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
|
||||
with patch.object(
|
||||
connection,
|
||||
|
@ -1317,7 +1313,7 @@ async def test_bluetooth_gatt_start_notify_fails(
|
|||
await client.bluetooth_gatt_start_notify(1234, 1, on_bluetooth_gatt_notify)
|
||||
|
||||
assert (
|
||||
len(list(itertools.chain(*connection._get_message_handlers().values())))
|
||||
len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
== handlers_before
|
||||
)
|
||||
|
||||
|
@ -1769,9 +1765,7 @@ async def test_bluetooth_device_connect_cancelled(
|
|||
client, connection, transport, protocol = api_client
|
||||
states = []
|
||||
|
||||
handlers_before = len(
|
||||
list(itertools.chain(*connection._get_message_handlers().values()))
|
||||
)
|
||||
handlers_before = len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
|
||||
def on_bluetooth_connection_state(connected: bool, mtu: int, error: int) -> None:
|
||||
states.append((connected, mtu, error))
|
||||
|
@ -1795,9 +1789,7 @@ async def test_bluetooth_device_connect_cancelled(
|
|||
await connect_task
|
||||
assert states == []
|
||||
|
||||
handlers_after = len(
|
||||
list(itertools.chain(*connection._get_message_handlers().values()))
|
||||
)
|
||||
handlers_after = len(list(itertools.chain(*connection._message_handlers.values())))
|
||||
# Make sure we do not leak message handlers
|
||||
assert handlers_after == handlers_before
|
||||
|
||||
|
|
|
@ -170,6 +170,10 @@ async def test_requires_encryption_propagates(conn: APIConnection):
|
|||
mock_data_received(protocol, b"\x01\x00\x00")
|
||||
await task
|
||||
|
||||
await asyncio.sleep(0)
|
||||
await asyncio.sleep(0)
|
||||
assert isinstance(conn._fatal_exception, RequiresEncryptionAPIError)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_plaintext_connection(
|
||||
|
|
Loading…
Reference in New Issue