1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 13:12:22 +01:00
This commit is contained in:
J. Nick Koston
2025-09-21 09:55:01 -06:00
parent 1d6c6c917a
commit e2fd5190c2

View File

@@ -31,6 +31,29 @@ def mock_socket() -> MockType:
return socket
@pytest.fixture
def mock_file() -> io.BytesIO:
"""Create a mock firmware file for testing."""
return io.BytesIO(b"firmware content here")
@pytest.fixture
def mock_time():
"""Mock time-related functions for consistent testing."""
with (
patch("time.sleep"),
patch("time.perf_counter", side_effect=[0, 1]),
) as mocks:
yield mocks
@pytest.fixture
def mock_random():
"""Mock random for predictable test values."""
with patch("random.random", return_value=0.123456) as mock_rand:
yield mock_rand
def test_recv_decode_with_decode(mock_socket) -> None:
"""Test recv_decode with decode=True returns list."""
mock_socket.recv.return_value = b"\x01\x02\x03"