1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
"""Test zigpy backports."""
from enum import auto
import pytest
from zigpy.backports.enum import StrEnum
def test_strenum() -> None:
"""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()
|