mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 01:07:10 +00:00
Add tests
This commit is contained in:
parent
415122a074
commit
a6a39103d7
@ -138,7 +138,7 @@ def deprecated_function[**_P, _R](
|
|||||||
return deprecated_decorator
|
return deprecated_decorator
|
||||||
|
|
||||||
|
|
||||||
def deprecate_hass_binding[**_P, _T](
|
def deprecated_hass_binding[**_P, _T](
|
||||||
breaks_in_ha_version: str | None = None,
|
breaks_in_ha_version: str | None = None,
|
||||||
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
|
||||||
"""Decorate function to indicate that first argument hass will be ignored."""
|
"""Decorate function to indicate that first argument hass will be ignored."""
|
||||||
@ -148,7 +148,7 @@ def deprecate_hass_binding[**_P, _T](
|
|||||||
def _inner(*args: _P.args, **kwargs: _P.kwargs) -> _T:
|
def _inner(*args: _P.args, **kwargs: _P.kwargs) -> _T:
|
||||||
from homeassistant.core import HomeAssistant # noqa: PLC0415
|
from homeassistant.core import HomeAssistant # noqa: PLC0415
|
||||||
|
|
||||||
if isinstance(args[0], HomeAssistant):
|
if len(args) > 0 and isinstance(args[0], HomeAssistant):
|
||||||
_print_deprecation_warning_internal(
|
_print_deprecation_warning_internal(
|
||||||
"hass",
|
"hass",
|
||||||
func.__module__,
|
func.__module__,
|
||||||
|
@ -57,7 +57,7 @@ from . import (
|
|||||||
template,
|
template,
|
||||||
translation,
|
translation,
|
||||||
)
|
)
|
||||||
from .deprecation import deprecate_hass_binding, deprecated_class, deprecated_function
|
from .deprecation import deprecated_class, deprecated_function, deprecated_hass_binding
|
||||||
from .selector import TargetSelector
|
from .selector import TargetSelector
|
||||||
from .typing import ConfigType, TemplateVarsType, VolDictType, VolSchemaType
|
from .typing import ConfigType, TemplateVarsType, VolDictType, VolSchemaType
|
||||||
|
|
||||||
@ -986,7 +986,7 @@ def async_register_admin_service(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@deprecate_hass_binding(breaks_in_ha_version="2026.2")
|
@deprecated_hass_binding(breaks_in_ha_version="2026.2")
|
||||||
@callback
|
@callback
|
||||||
def verify_domain_control(
|
def verify_domain_control(
|
||||||
domain: str,
|
domain: str,
|
||||||
|
@ -17,6 +17,7 @@ from homeassistant.helpers.deprecation import (
|
|||||||
check_if_deprecated_constant,
|
check_if_deprecated_constant,
|
||||||
deprecated_class,
|
deprecated_class,
|
||||||
deprecated_function,
|
deprecated_function,
|
||||||
|
deprecated_hass_binding,
|
||||||
deprecated_substitute,
|
deprecated_substitute,
|
||||||
dir_with_deprecated_constants,
|
dir_with_deprecated_constants,
|
||||||
get_deprecated,
|
get_deprecated,
|
||||||
@ -638,3 +639,41 @@ def test_enum_with_deprecated_members_integration_not_found(
|
|||||||
TestEnum.DOGS # noqa: B018
|
TestEnum.DOGS # noqa: B018
|
||||||
|
|
||||||
assert len(caplog.record_tuples) == 0
|
assert len(caplog.record_tuples) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("breaks_in_ha_version", "extra_msg"),
|
||||||
|
[
|
||||||
|
(None, ""),
|
||||||
|
("2099.1", " It will be removed in HA Core 2099.1."),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_deprecated_hass_binding(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
breaks_in_ha_version: str | None,
|
||||||
|
extra_msg: str,
|
||||||
|
) -> None:
|
||||||
|
"""Test deprecated_hass_binding decorator."""
|
||||||
|
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
@deprecated_hass_binding(breaks_in_ha_version=breaks_in_ha_version)
|
||||||
|
def mock_deprecated_function():
|
||||||
|
calls.append("called")
|
||||||
|
|
||||||
|
mock_deprecated_function()
|
||||||
|
assert (
|
||||||
|
"The deprecated argument hass was passed to mock_deprecated_function."
|
||||||
|
f"{extra_msg}"
|
||||||
|
" Use mock_deprecated_function without hass argument instead"
|
||||||
|
) not in caplog.text
|
||||||
|
assert len(calls) == 1
|
||||||
|
|
||||||
|
mock_deprecated_function(hass)
|
||||||
|
assert (
|
||||||
|
"The deprecated argument hass was passed to mock_deprecated_function."
|
||||||
|
f"{extra_msg}"
|
||||||
|
" Use mock_deprecated_function without hass argument instead"
|
||||||
|
) in caplog.text
|
||||||
|
assert len(calls) == 2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user