Fix test_wait_template_with_utcnow (#45356)

This commit is contained in:
J. Nick Koston 2021-01-20 16:56:00 -06:00 committed by GitHub
parent 96448c6778
commit 243014bff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -824,9 +824,11 @@ async def test_wait_template_with_utcnow(hass):
start_time = dt_util.utcnow().replace(minute=1) + timedelta(hours=48)
try:
hass.async_create_task(script_obj.async_run(context=Context()))
await asyncio.wait_for(wait_started_flag.wait(), 1)
assert script_obj.is_running
non_maching_time = start_time.replace(hour=3)
with patch("homeassistant.util.dt.utcnow", return_value=non_maching_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):
@ -848,13 +850,17 @@ async def test_wait_template_with_utcnow_no_match(hass):
timed_out = False
try:
hass.async_create_task(script_obj.async_run(context=Context()))
await asyncio.wait_for(wait_started_flag.wait(), 1)
assert script_obj.is_running
non_maching_time = start_time.replace(hour=3)
with patch("homeassistant.util.dt.utcnow", return_value=non_maching_time):
async_fire_time_changed(hass, non_maching_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_maching_time = start_time.replace(hour=4)
with patch(
"homeassistant.util.dt.utcnow", return_value=second_non_maching_time
):
async_fire_time_changed(hass, second_non_maching_time)
with timeout(0.1):
await hass.async_block_till_done()