fix mocking

This commit is contained in:
J. Nick Koston 2023-12-09 18:06:58 -10:00
parent f0df2fff21
commit 224ef60faf
No known key found for this signature in database
2 changed files with 12 additions and 10 deletions

View File

@ -373,12 +373,12 @@ class APIConnection:
aiohappyeyeballs.pop_addr_infos_interleave(addr_infos, interleave) aiohappyeyeballs.pop_addr_infos_interleave(addr_infos, interleave)
if sock is None: if sock is None:
if isinstance(last_exception, OSError): if isinstance(last_exception, asyncio_TimeoutError):
raise SocketAPIError( raise TimeoutAPIError(
f"Error connecting to {addr_infos}: {last_exception}" f"Timeout while connecting to {addrs}"
) from last_exception ) from last_exception
raise SocketAPIError( raise SocketAPIError(
f"Timeout while connecting to {addr_infos}" f"Error connecting to {addrs}: {last_exception}"
) from last_exception ) from last_exception
self._socket = sock self._socket = sock

View File

@ -39,12 +39,14 @@ def async_zeroconf():
@pytest.fixture @pytest.fixture
def resolve_host(): def resolve_host():
with patch("aioesphomeapi.host_resolver.async_resolve_host") as func: with patch("aioesphomeapi.host_resolver.async_resolve_host") as func:
func.return_value = AddrInfo( func.return_value = [
family=socket.AF_INET, AddrInfo(
type=socket.SOCK_STREAM, family=socket.AF_INET,
proto=socket.IPPROTO_TCP, type=socket.SOCK_STREAM,
sockaddr=IPv4Sockaddr("10.0.0.512", 6052), proto=socket.IPPROTO_TCP,
) sockaddr=IPv4Sockaddr("10.0.0.512", 6052),
)
]
yield func yield func