From bbc9390f9193badf3655f667ce6c05b97d96e095 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Aug 2024 11:07:55 -1000 Subject: [PATCH] win32 test fixes --- tests/test_connection.py | 15 ++++++++++----- tests/test_host_resolver.py | 4 ++-- tests/test_log_runner.py | 9 ++++++--- tests/test_model.py | 12 ++++-------- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index 54898c8..debe194 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -1,15 +1,16 @@ from __future__ import annotations import asyncio -import logging -import socket +from contextlib import suppress from datetime import timedelta from functools import partial +import logging +import socket from typing import Callable, cast from unittest.mock import AsyncMock, MagicMock, call, create_autospec, patch -import pytest from google.protobuf import message +import pytest from aioesphomeapi import APIClient from aioesphomeapi._frame_helper import APIPlaintextFrameHelper @@ -59,7 +60,7 @@ KEEP_ALIVE_TIMEOUT_RATIO = 4.5 async def test_connect( plaintext_connect_task_no_login: tuple[ APIConnection, asyncio.Transport, APIPlaintextFrameHelper, asyncio.Task - ] + ], ) -> None: """Test that a plaintext connection works.""" conn, transport, protocol, connect_task = plaintext_connect_task_no_login @@ -268,7 +269,11 @@ async def test_start_connection_cannot_increase_recv_buffer( mock_socket.fileno.return_value = 1 mock_socket.getpeername.return_value = ("10.0.0.512", 323) mock_socket.setsockopt = _setsockopt - mock_socket.sendmsg.side_effect = OSError("Socket error") + with suppress(AttributeError): + mock_socket.sendmsg.side_effect = OSError("Socket error") + mock_socket.send.side_effect = OSError("Socket error") + mock_socket.sendto.side_effect = OSError("Socket error") + aiohappyeyeballs_start_connection.return_value = mock_socket with patch.object( diff --git a/tests/test_host_resolver.py b/tests/test_host_resolver.py index 30a7882..24a6f2f 100644 --- a/tests/test_host_resolver.py +++ b/tests/test_host_resolver.py @@ -1,15 +1,15 @@ from __future__ import annotations import asyncio -import socket from ipaddress import IPv6Address, ip_address +import socket from unittest.mock import AsyncMock, MagicMock, patch import pytest from zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf -import aioesphomeapi.host_resolver as hr from aioesphomeapi.core import APIConnectionError, ResolveAPIError +import aioesphomeapi.host_resolver as hr from aioesphomeapi.zeroconf import ZeroconfManager diff --git a/tests/test_log_runner.py b/tests/test_log_runner.py index 9774736..1f62687 100644 --- a/tests/test_log_runner.py +++ b/tests/test_log_runner.py @@ -5,12 +5,15 @@ from datetime import timedelta from functools import partial from unittest.mock import MagicMock, patch -import pytest from google.protobuf import message +import pytest from aioesphomeapi._frame_helper.plain_text import APIPlaintextFrameHelper -from aioesphomeapi.api_pb2 import SubscribeLogsResponse # type: ignore -from aioesphomeapi.api_pb2 import DisconnectRequest, DisconnectResponse +from aioesphomeapi.api_pb2 import ( + DisconnectRequest, + DisconnectResponse, + SubscribeLogsResponse, # type: ignore +) from aioesphomeapi.client import APIClient from aioesphomeapi.connection import APIConnection from aioesphomeapi.core import APIConnectionError diff --git a/tests/test_model.py b/tests/test_model.py index 3c2fcdb..c1a54d4 100644 --- a/tests/test_model.py +++ b/tests/test_model.py @@ -2,8 +2,8 @@ from __future__ import annotations from dataclasses import dataclass, field -import pytest from google.protobuf import message +import pytest from aioesphomeapi.api_pb2 import ( AlarmControlPanelStateResponse, @@ -65,14 +65,10 @@ from aioesphomeapi.model import ( APIVersion, BinarySensorInfo, BinarySensorState, -) -from aioesphomeapi.model import ( BluetoothGATTCharacteristic as BluetoothGATTCharacteristicModel, -) -from aioesphomeapi.model import BluetoothGATTDescriptor as BluetoothGATTDescriptorModel -from aioesphomeapi.model import BluetoothGATTService as BluetoothGATTServiceModel -from aioesphomeapi.model import BluetoothGATTServices as BluetoothGATTServicesModel -from aioesphomeapi.model import ( + BluetoothGATTDescriptor as BluetoothGATTDescriptorModel, + BluetoothGATTService as BluetoothGATTServiceModel, + BluetoothGATTServices as BluetoothGATTServicesModel, BluetoothProxyFeature, ButtonInfo, CameraInfo,