hass-core/tests/util/test_enum.py
Ville Skyttä 053c456199
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>
2021-11-22 18:14:15 +01:00

35 lines
712 B
Python

"""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()