Restore default timezone after electric_kiwi sensor tests (#116217)
parent
67f6a84f5d
commit
09a18459ff
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||
from collections.abc import Awaitable, Callable, Generator
|
||||
from time import time
|
||||
from unittest.mock import AsyncMock, patch
|
||||
import zoneinfo
|
||||
|
||||
from electrickiwi_api.model import AccountBalance, Hop, HopIntervals
|
||||
import pytest
|
||||
|
@ -24,8 +23,6 @@ CLIENT_ID = "1234"
|
|||
CLIENT_SECRET = "5678"
|
||||
REDIRECT_URI = "https://example.com/auth/external/callback"
|
||||
|
||||
TZ_NAME = "Pacific/Auckland"
|
||||
TIMEZONE = zoneinfo.ZoneInfo(TZ_NAME)
|
||||
YieldFixture = Generator[AsyncMock, None, None]
|
||||
ComponentSetup = Callable[[], Awaitable[bool]]
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
import zoneinfo
|
||||
|
||||
from freezegun import freeze_time
|
||||
import pytest
|
||||
|
@ -19,10 +20,22 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_registry import EntityRegistry
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .conftest import TIMEZONE, ComponentSetup, YieldFixture
|
||||
from .conftest import ComponentSetup, YieldFixture
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
DEFAULT_TIME_ZONE = dt_util.DEFAULT_TIME_ZONE
|
||||
TEST_TZ_NAME = "Pacific/Auckland"
|
||||
TEST_TIMEZONE = zoneinfo.ZoneInfo(TEST_TZ_NAME)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def restore_timezone():
|
||||
"""Restore default timezone."""
|
||||
yield
|
||||
|
||||
dt_util.set_default_time_zone(DEFAULT_TIME_ZONE)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("sensor", "sensor_state"),
|
||||
|
@ -124,8 +137,8 @@ async def test_check_and_move_time(ek_api: AsyncMock) -> None:
|
|||
"""Test correct time is returned depending on time of day."""
|
||||
hop = await ek_api(Mock()).get_hop()
|
||||
|
||||
test_time = datetime(2023, 6, 21, 18, 0, 0, tzinfo=TIMEZONE)
|
||||
dt_util.set_default_time_zone(TIMEZONE)
|
||||
test_time = datetime(2023, 6, 21, 18, 0, 0, tzinfo=TEST_TIMEZONE)
|
||||
dt_util.set_default_time_zone(TEST_TIMEZONE)
|
||||
|
||||
with freeze_time(test_time):
|
||||
value = _check_and_move_time(hop, "4:00 PM")
|
||||
|
|
Loading…
Reference in New Issue