Change device entry type to an StrEnum (#59940)

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Ville Skyttä
2021-11-22 19:14:15 +02:00
committed by GitHub
parent 4a5238efa5
commit 053c456199
45 changed files with 167 additions and 71 deletions

35
tests/util/test_enum.py Normal file
View File

@ -0,0 +1,35 @@
"""Test Home Assistant enum utils."""
from enum import auto
import pytest
from homeassistant.util.enum import StrEnum
def test_strenum():
"""Test StrEnum."""
class TestEnum(StrEnum):
Test = "test"
assert str(TestEnum.Test) == "test"
assert TestEnum.Test == "test"
assert TestEnum("test") is TestEnum.Test
assert TestEnum(TestEnum.Test) is TestEnum.Test
with pytest.raises(ValueError):
TestEnum(42)
with pytest.raises(ValueError):
TestEnum("str but unknown")
with pytest.raises(TypeError):
class FailEnum(StrEnum):
Test = 42
with pytest.raises(TypeError):
class FailEnum2(StrEnum):
Test = auto()