mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Centralize duplicate fixtures in rainforest_raven tests (#118945)
This commit is contained in:
parent
7eda8aafc8
commit
c373e36995
@ -17,7 +17,7 @@ from .const import (
|
||||
from tests.common import AsyncMock, MockConfigEntry
|
||||
|
||||
|
||||
def create_mock_device():
|
||||
def create_mock_device() -> AsyncMock:
|
||||
"""Create a mock instance of RAVEnStreamDevice."""
|
||||
device = AsyncMock()
|
||||
|
||||
@ -33,7 +33,7 @@ def create_mock_device():
|
||||
return device
|
||||
|
||||
|
||||
def create_mock_entry(no_meters=False):
|
||||
def create_mock_entry(no_meters: bool = False) -> MockConfigEntry:
|
||||
"""Create a mock config entry for a RAVEn device."""
|
||||
return MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
33
tests/components/rainforest_raven/conftest.py
Normal file
33
tests/components/rainforest_raven/conftest.py
Normal file
@ -0,0 +1,33 @@
|
||||
"""Fixtures for the Rainforest RAVEn tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import create_mock_device, create_mock_entry
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device() -> Generator[AsyncMock, None, None]:
|
||||
"""Mock a functioning RAVEn device."""
|
||||
mock_device = create_mock_device()
|
||||
with patch(
|
||||
"homeassistant.components.rainforest_raven.coordinator.RAVEnSerialDevice",
|
||||
return_value=mock_device,
|
||||
):
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_entry(hass: HomeAssistant, mock_device: AsyncMock) -> MockConfigEntry:
|
||||
"""Mock a functioning RAVEn config entry."""
|
||||
mock_entry = create_mock_entry()
|
||||
mock_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return mock_entry
|
@ -10,20 +10,7 @@ from homeassistant.components.rainforest_raven.coordinator import RAVEnDataCoord
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
|
||||
from . import create_mock_device, create_mock_entry
|
||||
|
||||
from tests.common import patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device():
|
||||
"""Mock a functioning RAVEn device."""
|
||||
mock_device = create_mock_device()
|
||||
with patch(
|
||||
"homeassistant.components.rainforest_raven.coordinator.RAVEnSerialDevice",
|
||||
return_value=mock_device,
|
||||
):
|
||||
yield mock_device
|
||||
from . import create_mock_entry
|
||||
|
||||
|
||||
async def test_coordinator_device_info(hass: HomeAssistant, mock_device):
|
||||
|
@ -8,35 +8,13 @@ from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.const import CONF_MAC
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import create_mock_device, create_mock_entry
|
||||
from . import create_mock_entry
|
||||
from .const import DEMAND, NETWORK_INFO, PRICE_CLUSTER, SUMMATION
|
||||
|
||||
from tests.common import patch
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device():
|
||||
"""Mock a functioning RAVEn device."""
|
||||
mock_device = create_mock_device()
|
||||
with patch(
|
||||
"homeassistant.components.rainforest_raven.coordinator.RAVEnSerialDevice",
|
||||
return_value=mock_device,
|
||||
):
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_entry(hass: HomeAssistant, mock_device):
|
||||
"""Mock a functioning RAVEn config entry."""
|
||||
mock_entry = create_mock_entry()
|
||||
mock_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return mock_entry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_entry_no_meters(hass: HomeAssistant, mock_device):
|
||||
"""Mock a RAVEn config entry with no meters."""
|
||||
|
@ -1,36 +1,9 @@
|
||||
"""Tests for the Rainforest RAVEn component initialisation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.rainforest_raven.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import create_mock_device, create_mock_entry
|
||||
|
||||
from tests.common import patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device():
|
||||
"""Mock a functioning RAVEn device."""
|
||||
mock_device = create_mock_device()
|
||||
with patch(
|
||||
"homeassistant.components.rainforest_raven.coordinator.RAVEnSerialDevice",
|
||||
return_value=mock_device,
|
||||
):
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_entry(hass: HomeAssistant, mock_device):
|
||||
"""Mock a functioning RAVEn config entry."""
|
||||
mock_entry = create_mock_entry()
|
||||
mock_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return mock_entry
|
||||
|
||||
|
||||
async def test_load_unload_entry(hass: HomeAssistant, mock_entry):
|
||||
"""Test load and unload."""
|
||||
|
@ -1,34 +1,7 @@
|
||||
"""Tests for the Rainforest RAVEn sensors."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import create_mock_device, create_mock_entry
|
||||
|
||||
from tests.common import patch
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_device():
|
||||
"""Mock a functioning RAVEn device."""
|
||||
mock_device = create_mock_device()
|
||||
with patch(
|
||||
"homeassistant.components.rainforest_raven.coordinator.RAVEnSerialDevice",
|
||||
return_value=mock_device,
|
||||
):
|
||||
yield mock_device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def mock_entry(hass: HomeAssistant, mock_device):
|
||||
"""Mock a functioning RAVEn config entry."""
|
||||
mock_entry = create_mock_entry()
|
||||
mock_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return mock_entry
|
||||
|
||||
|
||||
async def test_sensors(hass: HomeAssistant, mock_device, mock_entry):
|
||||
"""Test the sensors."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user