From c226d793d429fade7bdda68f3ad132f9cb05906b Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Tue, 19 Dec 2023 17:31:31 +0100 Subject: [PATCH] Move common function for testing derepcation constants to util (#106063) --- .../test_constant_deprecation/binary_sensor.py | 11 ++++++++--- .../test_constant_deprecation/util.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/testing_config/custom_components/test_constant_deprecation/util.py diff --git a/tests/testing_config/custom_components/test_constant_deprecation/binary_sensor.py b/tests/testing_config/custom_components/test_constant_deprecation/binary_sensor.py index e9e85dfb639..dda4d4f83f7 100644 --- a/tests/testing_config/custom_components/test_constant_deprecation/binary_sensor.py +++ b/tests/testing_config/custom_components/test_constant_deprecation/binary_sensor.py @@ -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_", +) diff --git a/tests/testing_config/custom_components/test_constant_deprecation/util.py b/tests/testing_config/custom_components/test_constant_deprecation/util.py new file mode 100644 index 00000000000..126bf8a7359 --- /dev/null +++ b/tests/testing_config/custom_components/test_constant_deprecation/util.py @@ -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