Migrate non-component tests to use freezegun/freezer (#105142)
This commit is contained in:
parent
00e87b9dff
commit
d1aa690c24
6 changed files with 247 additions and 236 deletions
|
@ -9,6 +9,7 @@ from types import MappingProxyType
|
|||
from unittest import mock
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -1346,13 +1347,13 @@ async def test_wait_template_with_utcnow(hass: HomeAssistant) -> None:
|
|||
|
||||
try:
|
||||
non_matching_time = start_time.replace(hour=3)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=non_matching_time):
|
||||
with freeze_time(non_matching_time):
|
||||
hass.async_create_task(script_obj.async_run(context=Context()))
|
||||
await asyncio.wait_for(wait_started_flag.wait(), 1)
|
||||
assert script_obj.is_running
|
||||
|
||||
match_time = start_time.replace(hour=12)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=match_time):
|
||||
with freeze_time(match_time):
|
||||
async_fire_time_changed(hass, match_time)
|
||||
except (AssertionError, asyncio.TimeoutError):
|
||||
await script_obj.async_stop()
|
||||
|
@ -1378,15 +1379,13 @@ async def test_wait_template_with_utcnow_no_match(hass: HomeAssistant) -> None:
|
|||
|
||||
try:
|
||||
non_matching_time = start_time.replace(hour=3)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=non_matching_time):
|
||||
with freeze_time(non_matching_time):
|
||||
hass.async_create_task(script_obj.async_run(context=Context()))
|
||||
await asyncio.wait_for(wait_started_flag.wait(), 1)
|
||||
assert script_obj.is_running
|
||||
|
||||
second_non_matching_time = start_time.replace(hour=4)
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow", return_value=second_non_matching_time
|
||||
):
|
||||
with freeze_time(second_non_matching_time):
|
||||
async_fire_time_changed(hass, second_non_matching_time)
|
||||
|
||||
async with asyncio.timeout(0.1):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue