mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Keep Supervisor helpers in Core and expose the registry fixture (#187268)
This commit is contained in:
@@ -17,7 +17,6 @@ authors = [
|
||||
# Dependency pins are synchronized by script.gen_requirements_all.
|
||||
dependencies = [
|
||||
"homeassistant",
|
||||
"aiohasupervisor==0.7.0",
|
||||
"bleak-retry-connector==4.7.1",
|
||||
"freezegun==1.5.5",
|
||||
"paho-mqtt==2.1.0",
|
||||
@@ -37,6 +36,7 @@ pytest_homeassistant = "pytest_homeassistant.bootstrap"
|
||||
|
||||
[project.optional-dependencies]
|
||||
bluetooth = [
|
||||
"aiohasupervisor==0.7.0",
|
||||
"aiousbwatcher==1.1.2",
|
||||
"bluetooth-adapters==2.4.0",
|
||||
"bluetooth-auto-recovery==1.6.4",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
"""Tests for Hass.io component."""
|
||||
|
||||
SUPERVISOR_TOKEN = "123456"
|
||||
@@ -709,6 +709,22 @@ def hass_config_dir() -> str:
|
||||
return get_test_config_dir()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entity_registry_enabled_by_default() -> Generator[None]:
|
||||
"""Test fixture that ensures all entities are enabled in the registry."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
|
||||
return_value=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.device_tracker.config_entry.ScannerEntity.entity_registry_enabled_default",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def custom_integrations_enabled() -> bool:
|
||||
"""Control custom integration loading."""
|
||||
@@ -2274,39 +2290,6 @@ def mock_bleak_scanner_start() -> Generator[MagicMock]:
|
||||
yield mock_bleak_scanner_start
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hassio_env(
|
||||
supervisor_is_connected: AsyncMock, supervisor_root_info: AsyncMock
|
||||
) -> Generator[None]:
|
||||
"""Fixture to inject hassio env."""
|
||||
from aiohasupervisor import SupervisorError # noqa: PLC0415
|
||||
|
||||
from .components.hassio import SUPERVISOR_TOKEN # noqa: PLC0415
|
||||
|
||||
supervisor_root_info.side_effect = SupervisorError()
|
||||
with (
|
||||
patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}),
|
||||
patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hassio_stubs(
|
||||
hassio_env: None,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
supervisor_client: AsyncMock,
|
||||
ingress_panels: AsyncMock,
|
||||
) -> None:
|
||||
"""Create mock hassio http client."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.coordinator.SupervisorIssuesCoordinator.async_refresh",
|
||||
):
|
||||
await async_setup_component(hass, "hassio", {})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def integration_frame_path() -> str:
|
||||
"""Return the path to the integration frame.
|
||||
|
||||
@@ -11,6 +11,7 @@ from homeassistant import loader
|
||||
from homeassistant.components.recorder import Recorder
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.http import HomeAssistantView
|
||||
from homeassistant.setup import async_setup_component
|
||||
from pytest_homeassistant import _paths
|
||||
@@ -156,3 +157,11 @@ def test_historical_recorder_schema(schema: str) -> None:
|
||||
"""Historical schema helpers must not import Core's test tree."""
|
||||
module = import_module(get_schema_module_path(schema))
|
||||
assert module.Base.metadata.tables
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
def test_entity_registry_enabled_by_default() -> None:
|
||||
"""Registry fixtures enable entities that are disabled by default."""
|
||||
entity = Entity()
|
||||
entity._attr_entity_registry_enabled_default = False
|
||||
assert entity.entity_registry_enabled_default
|
||||
|
||||
@@ -6,6 +6,7 @@ from functools import lru_cache
|
||||
from importlib.util import find_spec
|
||||
import inspect
|
||||
from ipaddress import IPv4Address, IPv4Network
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import string
|
||||
@@ -54,6 +55,8 @@ from aiohasupervisor.store import StoreClient
|
||||
from aiohasupervisor.supervisor import SupervisorManagementClient
|
||||
import probatio
|
||||
import pytest
|
||||
from pytest_homeassistant.test_util.aiohttp import AiohttpClientMocker
|
||||
from pytest_homeassistant.typing import ClientSessionGenerator
|
||||
|
||||
from homeassistant import components, loader
|
||||
from homeassistant.components import repairs
|
||||
@@ -87,6 +90,7 @@ from homeassistant.exceptions import HomeAssistantError, Unauthorized
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers.translation import async_get_translations
|
||||
from homeassistant.helpers.typing import VolSchemaType
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import yaml as yaml_util
|
||||
|
||||
from tests.common import QualityScaleStatus, get_quality_scale
|
||||
@@ -125,22 +129,6 @@ def prevent_io() -> Generator[None]:
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def entity_registry_enabled_by_default() -> Generator[None]:
|
||||
"""Test fixture that ensures all entities are enabled in the registry."""
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
|
||||
return_value=True,
|
||||
),
|
||||
patch(
|
||||
"homeassistant.components.device_tracker.config_entry.ScannerEntity.entity_registry_enabled_default",
|
||||
return_value=True,
|
||||
),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
# TTS test fixtures
|
||||
@pytest.fixture(name="mock_tts_get_cache_files")
|
||||
def mock_tts_get_cache_files_fixture() -> Generator[MagicMock]:
|
||||
@@ -858,6 +846,39 @@ def supervisor_client() -> Generator[AsyncMock]:
|
||||
yield supervisor_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def hassio_env(
|
||||
supervisor_is_connected: AsyncMock, supervisor_root_info: AsyncMock
|
||||
) -> Generator[None]:
|
||||
"""Fixture to inject hassio env."""
|
||||
from aiohasupervisor import SupervisorError # noqa: PLC0415
|
||||
|
||||
from .hassio import SUPERVISOR_TOKEN # noqa: PLC0415
|
||||
|
||||
supervisor_root_info.side_effect = SupervisorError()
|
||||
with (
|
||||
patch.dict(os.environ, {"SUPERVISOR": "127.0.0.1"}),
|
||||
patch.dict(os.environ, {"SUPERVISOR_TOKEN": SUPERVISOR_TOKEN}),
|
||||
):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def hassio_stubs(
|
||||
hassio_env: None,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
aioclient_mock: AiohttpClientMocker,
|
||||
supervisor_client: AsyncMock,
|
||||
ingress_panels: AsyncMock,
|
||||
) -> None:
|
||||
"""Create mock hassio http client."""
|
||||
with patch(
|
||||
"homeassistant.components.hassio.coordinator.SupervisorIssuesCoordinator.async_refresh",
|
||||
):
|
||||
await async_setup_component(hass, "hassio", {})
|
||||
|
||||
|
||||
def _validate_translation_placeholders(
|
||||
full_key: str,
|
||||
translation: str,
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""Compatibility imports for the Home Assistant pytest helpers."""
|
||||
"""Tests for the Supervisor integration."""
|
||||
|
||||
from pytest_homeassistant.components.hassio import SUPERVISOR_TOKEN as SUPERVISOR_TOKEN
|
||||
SUPERVISOR_TOKEN = "123456"
|
||||
|
||||
Reference in New Issue
Block a user