mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Improve type hints in rfxtrx tests (#123885)
This commit is contained in:
parent
cd382bcdda
commit
36f9b69923
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from collections.abc import Callable, Coroutine, Generator
|
||||||
|
from typing import Any
|
||||||
|
from unittest.mock import MagicMock, Mock, patch
|
||||||
|
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
@ -67,7 +69,7 @@ async def setup_rfx_test_cfg(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def transport_mock(hass):
|
def transport_mock() -> Generator[Mock]:
|
||||||
"""Fixture that make sure all transports are fake."""
|
"""Fixture that make sure all transports are fake."""
|
||||||
transport = Mock(spec=RFXtrxTransport)
|
transport = Mock(spec=RFXtrxTransport)
|
||||||
with (
|
with (
|
||||||
@ -78,14 +80,14 @@ async def transport_mock(hass):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
async def connect_mock(hass):
|
def connect_mock() -> Generator[MagicMock]:
|
||||||
"""Fixture that make sure connect class is mocked."""
|
"""Fixture that make sure connect class is mocked."""
|
||||||
with patch("RFXtrx.Connect") as connect:
|
with patch("RFXtrx.Connect") as connect:
|
||||||
yield connect
|
yield connect
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, name="rfxtrx")
|
@pytest.fixture(autouse=True, name="rfxtrx")
|
||||||
def rfxtrx_fixture(hass, connect_mock):
|
def rfxtrx_fixture(hass: HomeAssistant, connect_mock: MagicMock) -> Mock:
|
||||||
"""Fixture that cleans up threads from integration."""
|
"""Fixture that cleans up threads from integration."""
|
||||||
|
|
||||||
rfx = Mock(spec=Connect)
|
rfx = Mock(spec=Connect)
|
||||||
@ -114,19 +116,21 @@ def rfxtrx_fixture(hass, connect_mock):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="rfxtrx_automatic")
|
@pytest.fixture(name="rfxtrx_automatic")
|
||||||
async def rfxtrx_automatic_fixture(hass, rfxtrx):
|
async def rfxtrx_automatic_fixture(hass: HomeAssistant, rfxtrx: Mock) -> Mock:
|
||||||
"""Fixture that starts up with automatic additions."""
|
"""Fixture that starts up with automatic additions."""
|
||||||
await setup_rfx_test_cfg(hass, automatic_add=True, devices={})
|
await setup_rfx_test_cfg(hass, automatic_add=True, devices={})
|
||||||
return rfxtrx
|
return rfxtrx
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
async def timestep(hass):
|
def timestep(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
) -> Generator[Callable[[int], Coroutine[Any, Any, None]]]:
|
||||||
"""Step system time forward."""
|
"""Step system time forward."""
|
||||||
|
|
||||||
with freeze_time(utcnow()) as frozen_time:
|
with freeze_time(utcnow()) as frozen_time:
|
||||||
|
|
||||||
async def delay(seconds):
|
async def delay(seconds: int) -> None:
|
||||||
"""Trigger delay in system."""
|
"""Trigger delay in system."""
|
||||||
frozen_time.tick(delta=seconds)
|
frozen_time.tick(delta=seconds)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user