From 7c1f03932e3e483f23f7b416ec8d6c58e8225a2b Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Wed, 12 Oct 2022 15:46:51 -0400 Subject: [PATCH] Fix host reload test (#3945) --- tests/host/test_manager.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/host/test_manager.py b/tests/host/test_manager.py index b5ec62932..4cc57d91b 100644 --- a/tests/host/test_manager.py +++ b/tests/host/test_manager.py @@ -1,6 +1,8 @@ """Test host manager.""" from unittest.mock import PropertyMock, patch +import pytest + from supervisor.coresys import CoreSys from supervisor.dbus.agent import OSAgent from supervisor.dbus.const import MulticastProtocolEnabled @@ -10,21 +12,28 @@ from supervisor.dbus.systemd import Systemd from supervisor.dbus.timedate import TimeDate -async def test_load( +@pytest.fixture(name="coresys_dbus") +async def fixture_coresys_dbus( coresys: CoreSys, hostname: Hostname, systemd: Systemd, timedate: TimeDate, os_agent: OSAgent, resolved: Resolved, - dbus: list[str], -): - """Test manager load.""" +) -> CoreSys: + """Coresys with all dbus interfaces mock loaded.""" type(coresys.dbus).hostname = PropertyMock(return_value=hostname) type(coresys.dbus).systemd = PropertyMock(return_value=systemd) type(coresys.dbus).timedate = PropertyMock(return_value=timedate) type(coresys.dbus).agent = PropertyMock(return_value=os_agent) type(coresys.dbus).resolved = PropertyMock(return_value=resolved) + + yield coresys + + +async def test_load(coresys_dbus: CoreSys, dbus: list[str]): + """Test manager load.""" + coresys = coresys_dbus dbus.clear() with patch.object(coresys.host.sound, "update") as sound_update: @@ -45,10 +54,11 @@ async def test_load( ) -async def test_reload(coresys: CoreSys, dbus: list[str]): +async def test_reload(coresys_dbus: CoreSys, dbus: list[str]): """Test manager reload and ensure it does not unnecessarily recreate dbus objects.""" - await coresys.dbus.load() + coresys = coresys_dbus await coresys.host.load() + dbus.clear() with patch("supervisor.utils.dbus.DBus.connect") as connect, patch.object( coresys.host.sound, "update"