Fold duplicate subclass tests into existing tests, unpack address tuple in loop

This commit is contained in:
J. Nick Koston
2026-08-12 18:25:48 -05:00
parent 7b0541cd23
commit 1072d6b070
2 changed files with 7 additions and 22 deletions
+1 -2
View File
@@ -531,8 +531,7 @@ def run_ota_impl_(
MAX_UPLOAD_ATTEMPTS,
)
time.sleep(UPLOAD_RETRY_DELAY)
for r in res:
af, socktype, _, _, sa = r
for af, socktype, _, _, sa in res:
_LOGGER.info("Connecting to %s port %s...", sa[0], sa[1])
sock = socket.socket(af, socktype)
sock.settimeout(20.0)
+6 -20
View File
@@ -144,9 +144,11 @@ def test_receive_exactly_with_error_response(mock_socket: Mock) -> None:
with pytest.raises(
espota2.OTAError, match="receiving auth:.*Authentication invalid"
):
) as exc_info:
espota2.receive_exactly(mock_socket, 1, "auth", [espota2.RESPONSE_OK])
# Device-reported errors must stay plain OTAError, not the retryable kind
assert not isinstance(exc_info.value, espota2.OTANetworkError)
mock_socket.close.assert_called_once()
@@ -170,16 +172,6 @@ def test_receive_exactly_closed_connection_is_network_error(mock_socket: Mock) -
mock_socket.close.assert_called_once()
def test_receive_exactly_device_error_is_not_network_error(mock_socket: Mock) -> None:
"""Test receive_exactly keeps device-reported errors as plain OTAError."""
mock_socket.recv.return_value = bytes([espota2.RESPONSE_ERROR_AUTH_INVALID])
with pytest.raises(espota2.OTAError) as exc_info:
espota2.receive_exactly(mock_socket, 1, "auth", [espota2.RESPONSE_OK])
assert not isinstance(exc_info.value, espota2.OTANetworkError)
@pytest.mark.parametrize(
("error_code", "expected_msg"),
[
@@ -255,22 +247,16 @@ def test_check_error_unexpected_response() -> None:
espota2.check_error([0x7F], [espota2.RESPONSE_OK, espota2.RESPONSE_AUTH_OK])
def test_check_error_empty_data_is_network_error() -> None:
"""Test check_error raises the retryable OTANetworkError subclass on empty data."""
with pytest.raises(espota2.OTANetworkError):
espota2.check_error(b"", espota2.RESPONSE_OK)
def test_check_error_empty_data() -> None:
"""Test check_error raises error when device closes connection without responding."""
"""Test check_error raises the retryable OTANetworkError when the device closes the connection."""
with pytest.raises(
espota2.OTAError, match="Device closed connection without responding"
espota2.OTANetworkError, match="Device closed connection without responding"
):
espota2.check_error([], [espota2.RESPONSE_OK])
# Also test with empty bytes
with pytest.raises(
espota2.OTAError, match="Device closed connection without responding"
espota2.OTANetworkError, match="Device closed connection without responding"
):
espota2.check_error(b"", [espota2.RESPONSE_OK])