mirror of
https://github.com/esphome/esphome.git
synced 2025-09-22 21:22:22 +01:00
preen
This commit is contained in:
@@ -95,6 +95,13 @@ def mock_open_file() -> Generator[tuple[Mock, MagicMock]]:
|
||||
yield mock_open, mock_file
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_socket_constructor(mock_socket: Mock) -> Generator[Mock]:
|
||||
"""Mock socket.socket constructor to return our mock socket."""
|
||||
with patch("socket.socket", return_value=mock_socket) as mock_constructor:
|
||||
yield mock_constructor
|
||||
|
||||
|
||||
def test_recv_decode_with_decode(mock_socket: Mock) -> None:
|
||||
"""Test recv_decode with decode=True returns list."""
|
||||
mock_socket.recv.return_value = b"\x01\x02\x03"
|
||||
@@ -387,15 +394,15 @@ def test_perform_ota_upload_error(mock_socket: Mock, mock_file: io.BytesIO) -> N
|
||||
espota2.perform_ota(mock_socket, "", mock_file, "test.bin")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_socket_constructor", "mock_resolve_ip")
|
||||
def test_run_ota_impl_successful(
|
||||
mock_socket: Mock, tmp_path: Path, mock_resolve_ip: Mock, mock_perform_ota: Mock
|
||||
mock_socket: Mock, tmp_path: Path, mock_perform_ota: Mock
|
||||
) -> None:
|
||||
"""Test run_ota_impl_ with successful upload."""
|
||||
# Create a real firmware file
|
||||
firmware_file = tmp_path / "firmware.bin"
|
||||
firmware_file.write_bytes(b"firmware content")
|
||||
|
||||
with patch("socket.socket", return_value=mock_socket):
|
||||
# Run OTA with real file path
|
||||
result_code, result_host = espota2.run_ota_impl_(
|
||||
"test.local", 3232, "password", str(firmware_file)
|
||||
@@ -420,9 +427,8 @@ def test_run_ota_impl_successful(
|
||||
assert call_args[3] == str(firmware_file)
|
||||
|
||||
|
||||
def test_run_ota_impl_connection_failed(
|
||||
mock_socket: Mock, tmp_path: Path, mock_resolve_ip: Mock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_socket_constructor", "mock_resolve_ip")
|
||||
def test_run_ota_impl_connection_failed(mock_socket: Mock, tmp_path: Path) -> None:
|
||||
"""Test run_ota_impl_ when connection fails."""
|
||||
mock_socket.connect.side_effect = OSError("Connection refused")
|
||||
|
||||
@@ -430,7 +436,6 @@ def test_run_ota_impl_connection_failed(
|
||||
firmware_file = tmp_path / "firmware.bin"
|
||||
firmware_file.write_bytes(b"firmware content")
|
||||
|
||||
with patch("socket.socket", return_value=mock_socket):
|
||||
result_code, result_host = espota2.run_ota_impl_(
|
||||
"test.local", 3232, "password", str(firmware_file)
|
||||
)
|
||||
|
Reference in New Issue
Block a user