mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-24 20:35:55 +00:00
Update to python 3.11 (#4296)
This commit is contained in:
@@ -18,6 +18,7 @@ from supervisor.exceptions import (
|
||||
DockerAPIError,
|
||||
DockerNotFound,
|
||||
)
|
||||
from supervisor.plugins.dns import PluginDns
|
||||
from supervisor.utils import check_exception_chain
|
||||
|
||||
from tests.common import load_json_fixture
|
||||
@@ -164,3 +165,20 @@ async def test_addon_uninstall_removes_discovery(
|
||||
|
||||
assert coresys.addons.installed == []
|
||||
assert coresys.discovery.list_messages == []
|
||||
|
||||
|
||||
async def test_load(
|
||||
coresys: CoreSys, install_addon_ssh: Addon, caplog: pytest.LogCaptureFixture
|
||||
):
|
||||
"""Test addon manager load."""
|
||||
caplog.clear()
|
||||
|
||||
with patch.object(DockerInterface, "attach") as attach, patch.object(
|
||||
PluginDns, "write_hosts"
|
||||
) as write_hosts:
|
||||
await coresys.addons.load()
|
||||
|
||||
attach.assert_called_once_with(version=AwesomeVersion("9.2.1"))
|
||||
write_hosts.assert_called_once()
|
||||
|
||||
assert "Found 1 installed add-ons" in caplog.text
|
||||
|
||||
20
tests/homeassistant/test_module.py
Normal file
20
tests/homeassistant/test_module.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Test Homeassistant module."""
|
||||
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from supervisor.coresys import CoreSys
|
||||
from supervisor.docker.interface import DockerInterface
|
||||
|
||||
|
||||
async def test_load(coresys: CoreSys, tmp_supervisor_data: Path):
|
||||
"""Test homeassistant module load."""
|
||||
with open(tmp_supervisor_data / "homeassistant" / "secrets.yaml", "w") as secrets:
|
||||
secrets.write("hello: world\n")
|
||||
|
||||
with patch.object(DockerInterface, "attach") as attach:
|
||||
await coresys.homeassistant.load()
|
||||
|
||||
attach.assert_called_once()
|
||||
|
||||
assert coresys.homeassistant.secrets.secrets == {"hello": "world"}
|
||||
31
tests/plugins/test_plugin_manager.py
Normal file
31
tests/plugins/test_plugin_manager.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""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)
|
||||
@@ -15,6 +15,7 @@ from supervisor.exceptions import AddonsNotSupportedError, StoreJobError
|
||||
from supervisor.homeassistant.module import HomeAssistant
|
||||
from supervisor.store import StoreManager
|
||||
from supervisor.store.addon import AddonStore
|
||||
from supervisor.store.git import GitRepo
|
||||
from supervisor.store.repository import Repository
|
||||
|
||||
from tests.common import load_yaml_fixture
|
||||
@@ -231,3 +232,14 @@ async def test_install_unavailable_addon(
|
||||
await coresys.addons.install("local_ssh")
|
||||
|
||||
assert log in caplog.text
|
||||
|
||||
|
||||
async def test_reload(coresys: CoreSys):
|
||||
"""Test store reload."""
|
||||
await coresys.store.load()
|
||||
assert len(coresys.store.all) == 4
|
||||
|
||||
with patch.object(GitRepo, "pull") as git_pull:
|
||||
await coresys.store.reload()
|
||||
|
||||
assert git_pull.call_count == 3
|
||||
|
||||
Reference in New Issue
Block a user