Skip to content

Commit 35a4b68

Browse files
authored
Fix steamist tests opening sockets (home-assistant#156467)
1 parent b166818 commit 35a4b68

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Test fixtures for the Steamist integration."""
2+
3+
from collections.abc import Generator
4+
from unittest.mock import AsyncMock, MagicMock, patch
5+
6+
import pytest
7+
8+
9+
@pytest.fixture
10+
def mock_aio_discovery() -> Generator[MagicMock]:
11+
"""Mock AIODiscovery30303."""
12+
with patch(
13+
"homeassistant.components.steamist.discovery.AIODiscovery30303"
14+
) as mock_aio_discovery:
15+
mock_aio_discovery.return_value.async_scan = AsyncMock()
16+
yield mock_aio_discovery

tests/components/steamist/test_init.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def mock_single_broadcast_address():
4242
yield
4343

4444

45+
@pytest.mark.usefixtures("mock_aio_discovery")
4546
async def test_config_entry_reload(hass: HomeAssistant) -> None:
4647
"""Test that a config entry can be reloaded."""
4748
_, config_entry = await _async_setup_entry_with_status(
@@ -52,6 +53,7 @@ async def test_config_entry_reload(hass: HomeAssistant) -> None:
5253
assert config_entry.state is ConfigEntryState.NOT_LOADED
5354

5455

56+
@pytest.mark.usefixtures("mock_aio_discovery")
5557
async def test_config_entry_retry_later(hass: HomeAssistant) -> None:
5658
"""Test that a config entry retry on connection error."""
5759
config_entry = MockConfigEntry(

tests/components/steamist/test_sensor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import pytest
6+
57
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature, UnitOfTime
68
from homeassistant.core import HomeAssistant
79

@@ -12,6 +14,7 @@
1214
)
1315

1416

17+
@pytest.mark.usefixtures("mock_aio_discovery")
1518
async def test_steam_active(hass: HomeAssistant) -> None:
1619
"""Test that the sensors are setup with the expected values when steam is active."""
1720
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_ACTIVE)
@@ -23,6 +26,7 @@ async def test_steam_active(hass: HomeAssistant) -> None:
2326
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfTime.MINUTES
2427

2528

29+
@pytest.mark.usefixtures("mock_aio_discovery")
2630
async def test_steam_inactive(hass: HomeAssistant) -> None:
2731
"""Test that the sensors are setup with the expected values when steam is not active."""
2832
await _async_setup_entry_with_status(hass, MOCK_ASYNC_GET_STATUS_INACTIVE)

tests/components/steamist/test_switch.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from datetime import timedelta
66
from unittest.mock import AsyncMock
77

8+
import pytest
9+
810
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
911
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
1012
from homeassistant.core import HomeAssistant
@@ -19,6 +21,7 @@
1921
from tests.common import async_fire_time_changed
2022

2123

24+
@pytest.mark.usefixtures("mock_aio_discovery")
2225
async def test_steam_active(hass: HomeAssistant) -> None:
2326
"""Test that the switches are setup with the expected values when steam is active."""
2427
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:
3841
assert hass.states.get("switch.steam_active").state == STATE_OFF
3942

4043

44+
@pytest.mark.usefixtures("mock_aio_discovery")
4145
async def test_steam_inactive(hass: HomeAssistant) -> None:
4246
"""Test that the switches are setup with the expected values when steam is not active."""
4347
client, _ = await _async_setup_entry_with_status(

0 commit comments

Comments
 (0)