Use freezegun in utility_meter tests (#105123)
This commit is contained in:
parent
3f28354a00
commit
a16819e0e5
2 changed files with 14 additions and 15 deletions
|
@ -2,8 +2,8 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.select import (
|
||||
|
@ -95,7 +95,7 @@ async def test_services(hass: HomeAssistant, meter) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
|
@ -116,7 +116,7 @@ async def test_services(hass: HomeAssistant, meter) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now += timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
4,
|
||||
|
@ -144,7 +144,7 @@ async def test_services(hass: HomeAssistant, meter) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now += timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
5,
|
||||
|
@ -221,7 +221,7 @@ async def test_services_config_entry(hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
|
@ -242,7 +242,7 @@ async def test_services_config_entry(hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now += timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
4,
|
||||
|
@ -270,7 +270,7 @@ async def test_services_config_entry(hass: HomeAssistant) -> None:
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now += timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
5,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""The tests for the utility_meter sensor platform."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
|
@ -132,7 +131,7 @@ async def test_state(hass: HomeAssistant, yaml_config, config_entry_config) -> N
|
|||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
|
@ -166,7 +165,7 @@ async def test_state(hass: HomeAssistant, yaml_config, config_entry_config) -> N
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=20)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
|
@ -729,7 +728,7 @@ async def test_net_consumption(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
1,
|
||||
|
@ -803,7 +802,7 @@ async def test_non_net_consumption(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
1,
|
||||
|
@ -813,7 +812,7 @@ async def test_non_net_consumption(
|
|||
await hass.async_block_till_done()
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
None,
|
||||
|
@ -1148,7 +1147,7 @@ async def test_non_periodically_resetting_meter_with_tariffs(
|
|||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == UnitOfEnergy.KILO_WATT_HOUR
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=10)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
3,
|
||||
|
@ -1186,7 +1185,7 @@ async def test_non_periodically_resetting_meter_with_tariffs(
|
|||
assert state.attributes.get("status") == COLLECTING
|
||||
|
||||
now = dt_util.utcnow() + timedelta(seconds=20)
|
||||
with patch("homeassistant.util.dt.utcnow", return_value=now):
|
||||
with freeze_time(now):
|
||||
hass.states.async_set(
|
||||
entity_id,
|
||||
6,
|
||||
|
|
Loading…
Add table
Reference in a new issue