Use freezegun in airly tests (#99028)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"""Test init of Airly integration."""
|
"""Test init of Airly integration."""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM
|
from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM
|
||||||
@@ -11,7 +11,6 @@ from homeassistant.config_entries import ConfigEntryState
|
|||||||
from homeassistant.const import STATE_UNAVAILABLE
|
from homeassistant.const import STATE_UNAVAILABLE
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
from homeassistant.util.dt import utcnow
|
|
||||||
|
|
||||||
from . import API_POINT_URL, init_integration
|
from . import API_POINT_URL, init_integration
|
||||||
|
|
||||||
@@ -99,7 +98,9 @@ async def test_config_with_turned_off_station(
|
|||||||
|
|
||||||
|
|
||||||
async def test_update_interval(
|
async def test_update_interval(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
aioclient_mock: AiohttpClientMocker,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test correct update interval when the number of configured instances changes."""
|
"""Test correct update interval when the number of configured instances changes."""
|
||||||
REMAINING_REQUESTS = 15
|
REMAINING_REQUESTS = 15
|
||||||
@@ -135,10 +136,8 @@ async def test_update_interval(
|
|||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
update_interval = set_update_interval(instances, REMAINING_REQUESTS)
|
update_interval = set_update_interval(instances, REMAINING_REQUESTS)
|
||||||
future = utcnow() + update_interval
|
freezer.tick(update_interval)
|
||||||
with patch("homeassistant.util.dt.utcnow") as mock_utcnow:
|
async_fire_time_changed(hass)
|
||||||
mock_utcnow.return_value = future
|
|
||||||
async_fire_time_changed(hass, future)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# call_count should increase by one because we have one instance configured
|
# call_count should increase by one because we have one instance configured
|
||||||
@@ -172,9 +171,8 @@ async def test_update_interval(
|
|||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
update_interval = set_update_interval(instances, REMAINING_REQUESTS)
|
update_interval = set_update_interval(instances, REMAINING_REQUESTS)
|
||||||
future = utcnow() + update_interval
|
freezer.tick(update_interval)
|
||||||
mock_utcnow.return_value = future
|
async_fire_time_changed(hass)
|
||||||
async_fire_time_changed(hass, future)
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# call_count should increase by two because we have two instances configured
|
# call_count should increase by two because we have two instances configured
|
||||||
|
|||||||
Reference in New Issue
Block a user