win32 test fixes

This commit is contained in:
J. Nick Koston 2024-08-29 11:07:55 -10:00
parent b67b238eb3
commit bbc9390f91
No known key found for this signature in database
4 changed files with 22 additions and 18 deletions

View File

@ -1,15 +1,16 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import logging from contextlib import suppress
import socket
from datetime import timedelta from datetime import timedelta
from functools import partial from functools import partial
import logging
import socket
from typing import Callable, cast from typing import Callable, cast
from unittest.mock import AsyncMock, MagicMock, call, create_autospec, patch from unittest.mock import AsyncMock, MagicMock, call, create_autospec, patch
import pytest
from google.protobuf import message from google.protobuf import message
import pytest
from aioesphomeapi import APIClient from aioesphomeapi import APIClient
from aioesphomeapi._frame_helper import APIPlaintextFrameHelper from aioesphomeapi._frame_helper import APIPlaintextFrameHelper
@ -59,7 +60,7 @@ KEEP_ALIVE_TIMEOUT_RATIO = 4.5
async def test_connect( async def test_connect(
plaintext_connect_task_no_login: tuple[ plaintext_connect_task_no_login: tuple[
APIConnection, asyncio.Transport, APIPlaintextFrameHelper, asyncio.Task APIConnection, asyncio.Transport, APIPlaintextFrameHelper, asyncio.Task
] ],
) -> None: ) -> None:
"""Test that a plaintext connection works.""" """Test that a plaintext connection works."""
conn, transport, protocol, connect_task = plaintext_connect_task_no_login 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.fileno.return_value = 1
mock_socket.getpeername.return_value = ("10.0.0.512", 323) mock_socket.getpeername.return_value = ("10.0.0.512", 323)
mock_socket.setsockopt = _setsockopt 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 aiohappyeyeballs_start_connection.return_value = mock_socket
with patch.object( with patch.object(

View File

@ -1,15 +1,15 @@
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import socket
from ipaddress import IPv6Address, ip_address from ipaddress import IPv6Address, ip_address
import socket
from unittest.mock import AsyncMock, MagicMock, patch from unittest.mock import AsyncMock, MagicMock, patch
import pytest import pytest
from zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf from zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf
import aioesphomeapi.host_resolver as hr
from aioesphomeapi.core import APIConnectionError, ResolveAPIError from aioesphomeapi.core import APIConnectionError, ResolveAPIError
import aioesphomeapi.host_resolver as hr
from aioesphomeapi.zeroconf import ZeroconfManager from aioesphomeapi.zeroconf import ZeroconfManager

View File

@ -5,12 +5,15 @@ from datetime import timedelta
from functools import partial from functools import partial
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from google.protobuf import message from google.protobuf import message
import pytest
from aioesphomeapi._frame_helper.plain_text import APIPlaintextFrameHelper from aioesphomeapi._frame_helper.plain_text import APIPlaintextFrameHelper
from aioesphomeapi.api_pb2 import SubscribeLogsResponse # type: ignore from aioesphomeapi.api_pb2 import (
from aioesphomeapi.api_pb2 import DisconnectRequest, DisconnectResponse DisconnectRequest,
DisconnectResponse,
SubscribeLogsResponse, # type: ignore
)
from aioesphomeapi.client import APIClient from aioesphomeapi.client import APIClient
from aioesphomeapi.connection import APIConnection from aioesphomeapi.connection import APIConnection
from aioesphomeapi.core import APIConnectionError from aioesphomeapi.core import APIConnectionError

View File

@ -2,8 +2,8 @@ from __future__ import annotations
from dataclasses import dataclass, field from dataclasses import dataclass, field
import pytest
from google.protobuf import message from google.protobuf import message
import pytest
from aioesphomeapi.api_pb2 import ( from aioesphomeapi.api_pb2 import (
AlarmControlPanelStateResponse, AlarmControlPanelStateResponse,
@ -65,14 +65,10 @@ from aioesphomeapi.model import (
APIVersion, APIVersion,
BinarySensorInfo, BinarySensorInfo,
BinarySensorState, BinarySensorState,
)
from aioesphomeapi.model import (
BluetoothGATTCharacteristic as BluetoothGATTCharacteristicModel, BluetoothGATTCharacteristic as BluetoothGATTCharacteristicModel,
) BluetoothGATTDescriptor as BluetoothGATTDescriptorModel,
from aioesphomeapi.model import BluetoothGATTDescriptor as BluetoothGATTDescriptorModel BluetoothGATTService as BluetoothGATTServiceModel,
from aioesphomeapi.model import BluetoothGATTService as BluetoothGATTServiceModel BluetoothGATTServices as BluetoothGATTServicesModel,
from aioesphomeapi.model import BluetoothGATTServices as BluetoothGATTServicesModel
from aioesphomeapi.model import (
BluetoothProxyFeature, BluetoothProxyFeature,
ButtonInfo, ButtonInfo,
CameraInfo, CameraInfo,