2024-03-26 21:15:20 +00:00
|
|
|
"""Tests for the Ollama integration."""
|
|
|
|
|
2024-04-29 14:15:46 +00:00
|
|
|
from unittest.mock import patch
|
2024-03-26 21:15:20 +00:00
|
|
|
|
|
|
|
from httpx import ConnectError
|
|
|
|
import pytest
|
|
|
|
|
2024-04-29 14:15:46 +00:00
|
|
|
from homeassistant.components import ollama
|
|
|
|
from homeassistant.core import HomeAssistant
|
2024-03-26 21:15:20 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
("side_effect", "error"),
|
|
|
|
[
|
|
|
|
(ConnectError(message="Connect error"), "Connect error"),
|
|
|
|
(RuntimeError("Runtime error"), "Runtime error"),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
async def test_init_error(
|
|
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, caplog, side_effect, error
|
|
|
|
) -> None:
|
|
|
|
"""Test initialization errors."""
|
|
|
|
with patch(
|
|
|
|
"ollama.AsyncClient.list",
|
|
|
|
side_effect=side_effect,
|
|
|
|
):
|
|
|
|
assert await async_setup_component(hass, ollama.DOMAIN, {})
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert error in caplog.text
|