mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 02:26:01 +00:00
Merge remote-tracking branch 'origin/api-max-data-length-force' into integration
This commit is contained in:
@@ -149,17 +149,36 @@ def test_icon__invalid():
|
||||
|
||||
|
||||
def test_icon__max_length():
|
||||
"""Test that icons exceeding 63 characters are rejected."""
|
||||
# Exactly 63 chars should pass
|
||||
max_icon = "mdi:" + "a" * 59 # 63 chars total
|
||||
"""Test that icons exceeding 63 bytes are rejected."""
|
||||
# Exactly 63 bytes should pass
|
||||
max_icon = "mdi:" + "a" * 59 # 63 bytes total
|
||||
assert config_validation.icon(max_icon) == max_icon
|
||||
|
||||
# 64 chars should fail
|
||||
too_long = "mdi:" + "a" * 60 # 64 chars total
|
||||
# 64 bytes should fail
|
||||
too_long = "mdi:" + "a" * 60 # 64 bytes total
|
||||
with pytest.raises(Invalid, match="Icon string is too long"):
|
||||
config_validation.icon(too_long)
|
||||
|
||||
|
||||
def test_byte_length() -> None:
|
||||
"""Test ByteLength validator checks UTF-8 byte length, not char count."""
|
||||
validator = config_validation.ByteLength(max=10) # pylint: disable=no-member
|
||||
|
||||
# ASCII: 10 chars = 10 bytes, should pass
|
||||
assert validator("a" * 10) == "a" * 10
|
||||
|
||||
# ASCII: 11 chars = 11 bytes, should fail
|
||||
with pytest.raises(Invalid, match="too long.*11 bytes.*max 10"):
|
||||
validator("a" * 11)
|
||||
|
||||
# Multibyte: 3 chars × 3 bytes = 9 bytes, should pass
|
||||
assert validator("温度传") == "温度传"
|
||||
|
||||
# Multibyte: 4 chars × 3 bytes = 12 bytes, should fail
|
||||
with pytest.raises(Invalid, match="too long.*12 bytes.*max 10"):
|
||||
validator("温度传感")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", ("True", "YES", "on", "enAblE", True))
|
||||
def test_boolean__valid_true(value):
|
||||
assert config_validation.boolean(value) is True
|
||||
@@ -567,14 +586,23 @@ def test_validate_entity_name__slash_replaced_with_warning(
|
||||
|
||||
|
||||
def test_validate_entity_name__max_length() -> None:
|
||||
# 120 chars should pass
|
||||
# 120 bytes should pass
|
||||
assert config_validation._validate_entity_name("x" * 120) == "x" * 120
|
||||
|
||||
# 121 chars should fail
|
||||
with pytest.raises(Invalid, match="too long.*121 chars.*Maximum.*120"):
|
||||
# 121 bytes should fail
|
||||
with pytest.raises(Invalid, match="too long.*121 bytes.*Maximum.*120"):
|
||||
config_validation._validate_entity_name("x" * 121)
|
||||
|
||||
|
||||
def test_validate_entity_name__multibyte_byte_length() -> None:
|
||||
# 40 chars of 3-byte UTF-8 = 120 bytes, should pass
|
||||
assert config_validation._validate_entity_name("温" * 40) == "温" * 40
|
||||
|
||||
# 41 chars of 3-byte UTF-8 = 123 bytes, should fail (over 120 byte limit)
|
||||
with pytest.raises(Invalid, match="too long.*123 bytes.*Maximum.*120"):
|
||||
config_validation._validate_entity_name("温" * 41)
|
||||
|
||||
|
||||
def test_validate_entity_name__none_without_friendly_name() -> None:
|
||||
# When name is "None" and friendly_name is not set, it should fail
|
||||
CORE.friendly_name = None
|
||||
|
||||
Reference in New Issue
Block a user