Files
hacs_integration/tests/patch_time.py
Joakim Sørensen 13c1c4ba1d Use freezegun in tests and add last_fetched to snapshots (#3599)
* Use freezegun in tests and add last_fetched to snapshots

* lint

* Remove incorrect workaround

* Also patch the monotonic timer

* Set non UTC system timezone in tests

* Change to a fork of szenius/set-timezone

* Accept review comment

* Revert CI timezone to UTC

---------

Co-authored-by: Erik <erik@montnemery.com>
2024-04-11 12:47:39 +02:00

27 lines
623 B
Python

"""Patch time related functions.
Copied from Home Assistant Core.
"""
from __future__ import annotations
import datetime
import time
from homeassistant import runner, util
from homeassistant.util import dt as dt_util
def _utcnow() -> datetime.datetime:
"""Make utcnow patchable by freezegun."""
return datetime.datetime.now(tz=datetime.UTC)
def _monotonic() -> float:
"""Make monotonic patchable by freezegun."""
return time.monotonic()
dt_util.utcnow = _utcnow # type: ignore[assignment]
util.utcnow = _utcnow # type: ignore[assignment]
runner.monotonic = _monotonic # type: ignore[assignment]