supervisor/tests/test_coresys.py
Mike Degatano 7fd6dce55f
Migrate to Ruff for lint and format (#4852)
* Migrate to Ruff for lint and format

* Fix pylint issues

* DBus property sets into normal awaitable methods

* Fix tests relying on separate tasks in connect

* Fixes from feedback
2024-02-05 11:37:39 -05:00

45 lines
1.2 KiB
Python

"""Testing handling with CoreState."""
from datetime import timedelta
from aiohttp.hdrs import USER_AGENT
from supervisor.coresys import CoreSys
from supervisor.dbus.timedate import TimeDate
from supervisor.utils.dt import utcnow
async def test_timezone(run_dir, coresys: CoreSys):
"""Test write corestate to /run/supervisor."""
# pylint: disable=protected-access
coresys.host.sys_dbus._timedate = TimeDate()
# pylint: enable=protected-access
assert coresys.timezone == "UTC"
assert coresys.config.timezone is None
await coresys.dbus.timedate.connect(coresys.dbus.bus)
assert coresys.timezone == "Etc/UTC"
coresys.config.timezone = "Europe/Zurich"
assert coresys.timezone == "Europe/Zurich"
def test_now(coresys: CoreSys):
"""Test datetime now with local time."""
coresys.config.timezone = "Europe/Zurich"
zurich = coresys.now()
utc = utcnow()
assert zurich != utc
assert zurich - utc <= timedelta(hours=2)
def test_custom_user_agent(coresys: CoreSys):
"""Test custom useragent."""
assert (
"HomeAssistantSupervisor/99.9.9dev"
in coresys.websession._default_headers[USER_AGENT] # pylint: disable=protected-access
)