Fix failing escea test in connection with greeneye_monitor (#115237)
* Fix failing escea test in connection with greeneye_monitor * typing
This commit is contained in:
parent
ca5ed274cb
commit
44f8dbf86b
1 changed files with 10 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
||||||
"""Common fixtures for testing greeneye_monitor."""
|
"""Common fixtures for testing greeneye_monitor."""
|
||||||
|
|
||||||
|
from collections.abc import Generator
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
|
@ -98,17 +99,18 @@ def assert_sensor_registered(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def monitors() -> AsyncMock:
|
def monitors() -> Generator[AsyncMock, None, None]:
|
||||||
"""Provide a mock greeneye.Monitors object that has listeners and can add new monitors."""
|
"""Provide a mock greeneye.Monitors object that has listeners and can add new monitors."""
|
||||||
with patch("greeneye.Monitors", new=AsyncMock) as mock_monitors:
|
with patch("greeneye.Monitors", autospec=True) as mock_monitors:
|
||||||
add_listeners(mock_monitors)
|
mock = mock_monitors.return_value
|
||||||
mock_monitors.monitors = {}
|
add_listeners(mock)
|
||||||
|
mock.monitors = {}
|
||||||
|
|
||||||
def add_monitor(monitor: MagicMock) -> None:
|
def add_monitor(monitor: MagicMock) -> None:
|
||||||
"""Add the given mock monitor as a monitor with the given serial number, notifying any listeners on the Monitors object."""
|
"""Add the given mock monitor as a monitor with the given serial number, notifying any listeners on the Monitors object."""
|
||||||
serial_number = monitor.serial_number
|
serial_number = monitor.serial_number
|
||||||
mock_monitors.monitors[serial_number] = monitor
|
mock.monitors[serial_number] = monitor
|
||||||
mock_monitors.notify_all_listeners(monitor)
|
mock.notify_all_listeners(monitor)
|
||||||
|
|
||||||
mock_monitors.add_monitor = add_monitor
|
mock.add_monitor = add_monitor
|
||||||
yield mock_monitors
|
yield mock
|
||||||
|
|
Loading…
Add table
Reference in a new issue