Fix steamist tests opening sockets (#156467)

This commit is contained in:
Erik Montnemery
2025-11-12 19:01:21 +01:00
committed by GitHub
parent b166818ef4
commit 35a4b685b3
4 changed files with 26 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
"""Test fixtures for the Steamist integration."""
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
@pytest.fixture
def mock_aio_discovery() -> Generator[MagicMock]:
"""Mock AIODiscovery30303."""
with patch(
"homeassistant.components.steamist.discovery.AIODiscovery30303"
) as mock_aio_discovery:
mock_aio_discovery.return_value.async_scan = AsyncMock()
yield mock_aio_discovery
+2
View File
@@ -42,6 +42,7 @@ def mock_single_broadcast_address():
yield
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_config_entry_reload(hass: HomeAssistant) -> None:
"""Test that a config entry can be reloaded."""
_, config_entry = await _async_setup_entry_with_status(
@@ -52,6 +53,7 @@ async def test_config_entry_reload(hass: HomeAssistant) -> None:
assert config_entry.state is ConfigEntryState.NOT_LOADED
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_config_entry_retry_later(hass: HomeAssistant) -> None:
"""Test that a config entry retry on connection error."""
config_entry = MockConfigEntry(
+4
View File
@@ -2,6 +2,8 @@
from __future__ import annotations
import pytest
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime
from homeassistant.core import HomeAssistant
@@ -12,6 +14,7 @@ from . import (
)
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_steam_active(hass: HomeAssistant) -> None:
"""Test that the sensors are setup with the expected values when steam is active."""
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
@@ -23,6 +26,7 @@ async def test_steam_active(hass: HomeAssistant) -> None:
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_steam_inactive(hass: HomeAssistant) -> None:
"""Test that the sensors are setup with the expected values when steam is not active."""
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE)
+4
View File
@@ -5,6 +5,8 @@ from __future__ import annotations
from datetime import timedelta
from unittest.mock import AsyncMock
import pytest
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
@@ -19,6 +21,7 @@ from . import (
from tests.common import async_fire_time_changed
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_steam_active(hass: HomeAssistant) -> None:
"""Test that the switches are setup with the expected values when steam is active."""
client, _ = await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
@@ -38,6 +41,7 @@ async def test_steam_active(hass: HomeAssistant) -> None:
assert hass.states.get("switch.steam_active").state == STATE_OFF
@pytest.mark.usefixtures("mock_aio_discovery")
async def test_steam_inactive(hass: HomeAssistant) -> None:
"""Test that the switches are setup with the expected values when steam is not active."""
client, _ = await _async_setup_entry_with_status(