1
mirror of https://github.com/home-assistant/supervisor synced 2024-08-05 03:49:58 +02:00
ha-supervisor/tests/plugins/test_plugin_manager.py
2023-05-22 19:12:34 +02:00

32 lines
926 B
Python

"""Test plugin manager."""
from unittest.mock import patch
from supervisor.coresys import CoreSys
from supervisor.docker.interface import DockerInterface
def mock_awaitable_bool(value: bool):
"""Return a mock of an awaitable bool."""
async def _mock_bool(*args, **kwargs) -> bool:
return value
return _mock_bool
async def test_repair(coresys: CoreSys):
"""Test repair."""
with patch.object(DockerInterface, "install") as install:
# If instance exists, repair does nothing
with patch.object(DockerInterface, "exists", new=mock_awaitable_bool(True)):
await coresys.plugins.repair()
install.assert_not_called()
# If not, repair installs the image
with patch.object(DockerInterface, "exists", new=mock_awaitable_bool(False)):
await coresys.plugins.repair()
assert install.call_count == len(coresys.plugins.all_plugins)