mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 03:08:01 +02:00
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:
35
tests/util/test_enum.py
Normal file
35
tests/util/test_enum.py
Normal 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()
|
Reference in New Issue
Block a user