mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
[core] Add test for register_unit_of_measurement max length
This commit is contained in:
@@ -28,6 +28,7 @@ from esphome.core.entity_helpers import (
|
|||||||
get_base_entity_object_id,
|
get_base_entity_object_id,
|
||||||
register_device_class,
|
register_device_class,
|
||||||
register_icon,
|
register_icon,
|
||||||
|
register_unit_of_measurement,
|
||||||
setup_device_class,
|
setup_device_class,
|
||||||
setup_entity,
|
setup_entity,
|
||||||
setup_unit_of_measurement,
|
setup_unit_of_measurement,
|
||||||
@@ -925,6 +926,22 @@ def test_register_device_class_max_length() -> None:
|
|||||||
assert register_device_class("") == 0
|
assert register_device_class("") == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_register_unit_of_measurement_max_length() -> None:
|
||||||
|
"""Test register_unit_of_measurement rejects units exceeding 63 characters."""
|
||||||
|
# 63 chars should succeed
|
||||||
|
max_uom = "a" * 63
|
||||||
|
idx = register_unit_of_measurement(max_uom)
|
||||||
|
assert idx > 0
|
||||||
|
|
||||||
|
# 64 chars should fail
|
||||||
|
too_long = "a" * 64
|
||||||
|
with pytest.raises(ValueError, match="Unit of measurement string too long"):
|
||||||
|
register_unit_of_measurement(too_long)
|
||||||
|
|
||||||
|
# Empty string returns 0
|
||||||
|
assert register_unit_of_measurement("") == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_setup_entity_with_entity_category(
|
async def test_setup_entity_with_entity_category(
|
||||||
setup_test_environment: list[str],
|
setup_test_environment: list[str],
|
||||||
|
|||||||
Reference in New Issue
Block a user