mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Update binary_sensor tests to avoid patching utcnow (#93474)
This commit is contained in:
parent
3e84c374f4
commit
da5ad4a17d
@ -1,7 +1,7 @@
|
|||||||
"""The test for binary_sensor device automation."""
|
"""The test for binary_sensor device automation."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
|
from freezegun import freeze_time
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.automation as automation
|
import homeassistant.components.automation as automation
|
||||||
@ -285,8 +285,7 @@ async def test_if_fires_on_for_condition(
|
|||||||
|
|
||||||
sensor1 = platform.ENTITIES["battery"]
|
sensor1 = platform.ENTITIES["battery"]
|
||||||
|
|
||||||
with patch("homeassistant.core.dt_util.utcnow") as mock_utcnow:
|
with freeze_time(point1) as time_freeze:
|
||||||
mock_utcnow.return_value = point1
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
automation.DOMAIN,
|
automation.DOMAIN,
|
||||||
@ -324,7 +323,7 @@ async def test_if_fires_on_for_condition(
|
|||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
# Time travel 10 secs into the future
|
# Time travel 10 secs into the future
|
||||||
mock_utcnow.return_value = point2
|
time_freeze.move_to(point2)
|
||||||
hass.bus.async_fire("test_event1")
|
hass.bus.async_fire("test_event1")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
@ -335,7 +334,7 @@ async def test_if_fires_on_for_condition(
|
|||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
|
||||||
# Time travel 20 secs into the future
|
# Time travel 20 secs into the future
|
||||||
mock_utcnow.return_value = point3
|
time_freeze.move_to(point3)
|
||||||
hass.bus.async_fire("test_event1")
|
hass.bus.async_fire("test_event1")
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user