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)
if sock is None:
if isinstance(last_exception, OSError):
raise SocketAPIError(
f"Error connecting to {addr_infos}: {last_exception}"
if isinstance(last_exception, asyncio_TimeoutError):
raise TimeoutAPIError(
f"Timeout while connecting to {addrs}"
) from last_exception
raise SocketAPIError(
f"Timeout while connecting to {addr_infos}"
f"Error connecting to {addrs}: {last_exception}"
) from last_exception
self._socket = sock

View File

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