mirror of
https://github.com/home-assistant/core.git
synced 2025-11-11 12:00:52 +00:00
Add LogCaptureFixture type hints in tests (#118372)
This commit is contained in:
@@ -8,6 +8,7 @@ mode (e.g. yaml, ConfigEntry, etc) however some tests override and just run in
|
||||
relevant modes.
|
||||
"""
|
||||
|
||||
from collections.abc import Generator
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import patch
|
||||
@@ -48,14 +49,18 @@ def platforms() -> list[str]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def error_caplog(caplog):
|
||||
def error_caplog(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> Generator[pytest.LogCaptureFixture, None, None]:
|
||||
"""Fixture to capture nest init error messages."""
|
||||
with caplog.at_level(logging.ERROR, logger="homeassistant.components.nest"):
|
||||
yield caplog
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def warning_caplog(caplog):
|
||||
def warning_caplog(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> Generator[pytest.LogCaptureFixture, None, None]:
|
||||
"""Fixture to capture nest init warning messages."""
|
||||
with caplog.at_level(logging.WARNING, logger="homeassistant.components.nest"):
|
||||
yield caplog
|
||||
@@ -78,7 +83,9 @@ def failing_subscriber(subscriber_side_effect: Any) -> YieldFixture[FakeSubscrib
|
||||
yield subscriber
|
||||
|
||||
|
||||
async def test_setup_success(hass: HomeAssistant, error_caplog, setup_platform) -> None:
|
||||
async def test_setup_success(
|
||||
hass: HomeAssistant, error_caplog: pytest.LogCaptureFixture, setup_platform
|
||||
) -> None:
|
||||
"""Test successful setup."""
|
||||
await setup_platform()
|
||||
assert not error_caplog.records
|
||||
@@ -109,7 +116,10 @@ async def test_setup_configuration_failure(
|
||||
|
||||
@pytest.mark.parametrize("subscriber_side_effect", [SubscriberException()])
|
||||
async def test_setup_susbcriber_failure(
|
||||
hass: HomeAssistant, caplog, failing_subscriber, setup_base_platform
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
failing_subscriber,
|
||||
setup_base_platform,
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
await setup_base_platform()
|
||||
@@ -121,7 +131,7 @@ async def test_setup_susbcriber_failure(
|
||||
|
||||
|
||||
async def test_setup_device_manager_failure(
|
||||
hass: HomeAssistant, caplog, setup_base_platform
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, setup_base_platform
|
||||
) -> None:
|
||||
"""Test device manager api failure."""
|
||||
with (
|
||||
@@ -161,7 +171,7 @@ async def test_subscriber_auth_failure(
|
||||
|
||||
@pytest.mark.parametrize("subscriber_id", [(None)])
|
||||
async def test_setup_missing_subscriber_id(
|
||||
hass: HomeAssistant, warning_caplog, setup_base_platform
|
||||
hass: HomeAssistant, warning_caplog: pytest.LogCaptureFixture, setup_base_platform
|
||||
) -> None:
|
||||
"""Test missing subscriber id from configuration."""
|
||||
await setup_base_platform()
|
||||
@@ -174,7 +184,10 @@ async def test_setup_missing_subscriber_id(
|
||||
|
||||
@pytest.mark.parametrize("subscriber_side_effect", [(ConfigurationException())])
|
||||
async def test_subscriber_configuration_failure(
|
||||
hass: HomeAssistant, error_caplog, setup_base_platform, failing_subscriber
|
||||
hass: HomeAssistant,
|
||||
error_caplog: pytest.LogCaptureFixture,
|
||||
setup_base_platform,
|
||||
failing_subscriber,
|
||||
) -> None:
|
||||
"""Test configuration error."""
|
||||
await setup_base_platform()
|
||||
@@ -187,7 +200,7 @@ async def test_subscriber_configuration_failure(
|
||||
|
||||
@pytest.mark.parametrize("nest_test_config", [TEST_CONFIGFLOW_APP_CREDS])
|
||||
async def test_empty_config(
|
||||
hass: HomeAssistant, error_caplog, config, setup_platform
|
||||
hass: HomeAssistant, error_caplog: pytest.LogCaptureFixture, config, setup_platform
|
||||
) -> None:
|
||||
"""Test setup is a no-op with not config."""
|
||||
await setup_platform()
|
||||
|
||||
Reference in New Issue
Block a user