2018-05-01 17:35:23 +00:00
|
|
|
"""Fixtures for component testing."""
|
2022-03-14 08:50:55 +00:00
|
|
|
from collections.abc import Generator
|
2023-05-25 09:59:20 +00:00
|
|
|
from typing import Any
|
|
|
|
from unittest.mock import MagicMock, patch
|
2021-01-01 21:31:56 +00:00
|
|
|
|
2018-05-01 17:35:23 +00:00
|
|
|
import pytest
|
|
|
|
|
2020-08-12 14:08:33 +00:00
|
|
|
|
2021-04-25 18:16:38 +00:00
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
2023-03-26 13:21:19 +00:00
|
|
|
def patch_zeroconf_multiple_catcher() -> Generator[None, None, None]:
|
2021-04-25 18:16:38 +00:00
|
|
|
"""Patch zeroconf wrapper that detects if multiple instances are used."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.zeroconf.install_multiple_zeroconf_catcher",
|
|
|
|
side_effect=lambda zc: None,
|
|
|
|
):
|
|
|
|
yield
|
2020-08-12 14:08:33 +00:00
|
|
|
|
2018-11-21 19:55:21 +00:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
2023-03-26 13:21:19 +00:00
|
|
|
def prevent_io() -> Generator[None, None, None]:
|
2018-11-21 19:55:21 +00:00
|
|
|
"""Fixture to prevent certain I/O from happening."""
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
2022-07-07 08:57:44 +00:00
|
|
|
"homeassistant.components.http.ban.load_yaml_config_file",
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-11-21 19:55:21 +00:00
|
|
|
yield
|
2022-03-14 08:50:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-03-26 13:21:19 +00:00
|
|
|
def entity_registry_enabled_by_default() -> Generator[None, None, None]:
|
2022-03-14 08:50:55 +00:00
|
|
|
"""Test fixture that ensures all entities are enabled in the registry."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.helpers.entity.Entity.entity_registry_enabled_default",
|
|
|
|
return_value=True,
|
2023-03-26 13:21:19 +00:00
|
|
|
):
|
|
|
|
yield
|
2023-05-25 09:59:20 +00:00
|
|
|
|
|
|
|
|
2023-05-25 11:45:19 +00:00
|
|
|
# Blueprint test fixtures
|
|
|
|
@pytest.fixture(name="stub_blueprint_populate")
|
2023-05-26 06:13:13 +00:00
|
|
|
def stub_blueprint_populate_fixture() -> Generator[None, Any, None]:
|
2023-05-25 11:45:19 +00:00
|
|
|
"""Stub copying the blueprints to the config folder."""
|
|
|
|
from tests.components.blueprint.common import stub_blueprint_populate_fixture_helper
|
|
|
|
|
|
|
|
yield from stub_blueprint_populate_fixture_helper()
|
|
|
|
|
|
|
|
|
|
|
|
# TTS test fixtures
|
2023-05-25 09:59:20 +00:00
|
|
|
@pytest.fixture(name="mock_tts_get_cache_files")
|
|
|
|
def mock_tts_get_cache_files_fixture():
|
|
|
|
"""Mock the list TTS cache function."""
|
|
|
|
from tests.components.tts.common import mock_tts_get_cache_files_fixture_helper
|
|
|
|
|
|
|
|
yield from mock_tts_get_cache_files_fixture_helper()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="mock_tts_init_cache_dir")
|
|
|
|
def mock_tts_init_cache_dir_fixture(
|
|
|
|
init_tts_cache_dir_side_effect: Any,
|
|
|
|
) -> Generator[MagicMock, None, None]:
|
|
|
|
"""Mock the TTS cache dir in memory."""
|
|
|
|
from tests.components.tts.common import mock_tts_init_cache_dir_fixture_helper
|
|
|
|
|
|
|
|
yield from mock_tts_init_cache_dir_fixture_helper(init_tts_cache_dir_side_effect)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="init_tts_cache_dir_side_effect")
|
|
|
|
def init_tts_cache_dir_side_effect_fixture() -> Any:
|
|
|
|
"""Return the cache dir."""
|
|
|
|
from tests.components.tts.common import (
|
|
|
|
init_tts_cache_dir_side_effect_fixture_helper,
|
|
|
|
)
|
|
|
|
|
|
|
|
return init_tts_cache_dir_side_effect_fixture_helper()
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="mock_tts_cache_dir")
|
|
|
|
def mock_tts_cache_dir_fixture(
|
|
|
|
tmp_path, mock_tts_init_cache_dir, mock_tts_get_cache_files, request
|
|
|
|
):
|
|
|
|
"""Mock the TTS cache dir with empty dir."""
|
|
|
|
from tests.components.tts.common import mock_tts_cache_dir_fixture_helper
|
|
|
|
|
|
|
|
yield from mock_tts_cache_dir_fixture_helper(
|
|
|
|
tmp_path, mock_tts_init_cache_dir, mock_tts_get_cache_files, request
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="tts_mutagen_mock")
|
|
|
|
def tts_mutagen_mock_fixture():
|
|
|
|
"""Mock writing tags."""
|
|
|
|
from tests.components.tts.common import tts_mutagen_mock_fixture_helper
|
|
|
|
|
|
|
|
yield from tts_mutagen_mock_fixture_helper()
|