Move common function for testing derepcation constants to util (#106063)

This commit is contained in:
Robert Resch 2023-12-19 17:31:31 +01:00 committed by GitHub
parent 0e0fd39603
commit c226d793d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -1,7 +1,12 @@
"""Test deprecated binary sensor device classes."""
from functools import partial
from homeassistant.components import binary_sensor
from .util import import_and_test_deprecated_costant
def import_deprecated(device_class: binary_sensor.BinarySensorDeviceClass):
"""Import deprecated device class constant."""
getattr(binary_sensor, f"DEVICE_CLASS_{device_class.name}")
import_deprecated = partial(
import_and_test_deprecated_costant,
module=binary_sensor,
constant_prefix="DEVICE_CLASS_",
)

View File

@ -0,0 +1,11 @@
"""util module for test_constant_deprecation tests."""
from enum import Enum
from types import ModuleType
def import_and_test_deprecated_costant(
replacement: Enum, module: ModuleType, constant_prefix: str
) -> None:
"""Import and test deprecated constant."""
assert getattr(module, constant_prefix + replacement.name) == replacement