Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Nov 1, 2024
1 parent 01dfd91 commit f1c4dbb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tests/test__frame_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(self, *args: Any, writer: Any | None = None, **kwargs: Any) -> None
"""Swallow args."""
super().__init__(*args, **kwargs)
transport = MagicMock()
transport.write = writer or MagicMock()
transport.writelines = writer or MagicMock()
self.__transport = transport
self.connection_made(transport)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,7 @@ def on_bluetooth_connection_state(connected: bool, mtu: int, error: int) -> None

cancel = await connect_task
assert states == [(True, 23, 0)]
transport.write.assert_called_once_with(
transport.writelines.assert_called_once_with(
generate_plaintext_packet(
BluetoothDeviceRequest(
address=1234,
Expand Down Expand Up @@ -2133,13 +2133,13 @@ def on_bluetooth_connection_state(connected: bool, mtu: int, error: int) -> None
)
await asyncio.sleep(0)
# The connect request should be written
assert len(transport.write.mock_calls) == 1
assert len(transport.writelines.mock_calls) == 1
await asyncio.sleep(0)
await asyncio.sleep(0)
await asyncio.sleep(0)
# Now that we timed out, the disconnect
# request should be written
assert len(transport.write.mock_calls) == 2
assert len(transport.writelines.mock_calls) == 2
response: message.Message = BluetoothDeviceConnectionResponse(
address=1234, connected=False, mtu=23, error=8
)
Expand Down Expand Up @@ -2177,7 +2177,7 @@ def on_bluetooth_connection_state(connected: bool, mtu: int, error: int) -> None
)
await asyncio.sleep(0)
# The connect request should be written
assert len(transport.write.mock_calls) == 1
assert len(transport.writelines.mock_calls) == 1
connect_task.cancel()
with pytest.raises(asyncio.CancelledError):
await connect_task
Expand Down
20 changes: 10 additions & 10 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def test_timeout_sending_message(
with patch("aioesphomeapi.connection.DISCONNECT_RESPONSE_TIMEOUT", 0.0):
await conn.disconnect()

transport.write.assert_called_with(b"\x00\x00\x05")
transport.writelines.assert_called_with(b"\x00\x00\x05")

assert "disconnect request failed" in caplog.text
assert " Timeout waiting for DisconnectResponse after 0.0s" in caplog.text
Expand Down Expand Up @@ -152,7 +152,7 @@ async def test_disconnect_when_not_fully_connected(
):
await connect_task

transport.write.assert_called_with(b"\x00\x00\x05")
transport.writelines.assert_called_with(b"\x00\x00\x05")

assert "disconnect request failed" in caplog.text
assert " Timeout waiting for DisconnectResponse after 0.0s" in caplog.text
Expand Down Expand Up @@ -506,7 +506,7 @@ def _create_failing_mock_transport_protocol(
) -> tuple[asyncio.Transport, APIPlaintextFrameHelperHandshakeException]:
protocol: APIPlaintextFrameHelperHandshakeException = create_func()
protocol._transport = cast(asyncio.Transport, transport)
protocol._writelines = transport.write
protocol._writelines = transport.writelines
protocol.ready_future.set_exception(exception)
connected.set()
return transport, protocol
Expand Down Expand Up @@ -906,9 +906,9 @@ async def test_ping_disconnects_after_no_responses(
async_fire_time_changed(
start_time + timedelta(seconds=KEEP_ALIVE_INTERVAL * count)
)
assert transport.write.call_count == count
assert transport.writelines.call_count == count
expected_calls.append(call(ping_request_bytes))
assert transport.write.mock_calls == expected_calls
assert transport.writelines.mock_calls == expected_calls

assert conn.is_connected is True

Expand All @@ -917,7 +917,7 @@ async def test_ping_disconnects_after_no_responses(
start_time
+ timedelta(seconds=KEEP_ALIVE_INTERVAL * (max_pings_to_disconnect_after + 1))
)
assert transport.write.call_count == max_pings_to_disconnect_after + 1
assert transport.writelines.call_count == max_pings_to_disconnect_after + 1

assert conn.is_connected is False

Expand Down Expand Up @@ -947,8 +947,8 @@ async def test_ping_does_not_disconnect_if_we_get_responses(
send_ping_response(protocol)

# We should only send 1 ping request if we are getting responses
assert transport.write.call_count == 1
assert transport.write.mock_calls == [call(ping_request_bytes)]
assert transport.writelines.call_count == 1
assert transport.writelines.mock_calls == [call(ping_request_bytes)]

# We should disconnect if we are getting ping responses
assert conn.is_connected is True
Expand Down Expand Up @@ -979,8 +979,8 @@ async def test_respond_to_ping_request(
send_ping_request(protocol)
# We should respond to ping requests
ping_response_bytes = b"\x00\x00\x08"
assert transport.write.call_count == 1
assert transport.write.mock_calls == [call(ping_response_bytes)]
assert transport.writelines.call_count == 1
assert transport.writelines.mock_calls == [call(ping_response_bytes)]


@pytest.mark.asyncio
Expand Down

0 comments on commit f1c4dbb

Please sign in to comment.