diff options
Diffstat (limited to 'tests/test_enum.py')
-rw-r--r-- | tests/test_enum.py | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/test_enum.py b/tests/test_enum.py new file mode 100644 index 0000000..807e785 --- /dev/null +++ b/tests/test_enum.py @@ -0,0 +1,79 @@ +from typing import ( + Optional, + Tuple, +) + +import pytest + +import aristaproto + + +class Colour(aristaproto.Enum): + RED = 1 + GREEN = 2 + BLUE = 3 + + +PURPLE = Colour.__new__(Colour, name=None, value=4) + + +@pytest.mark.parametrize( + "member, str_value", + [ + (Colour.RED, "RED"), + (Colour.GREEN, "GREEN"), + (Colour.BLUE, "BLUE"), + ], +) +def test_str(member: Colour, str_value: str) -> None: + assert str(member) == str_value + + +@pytest.mark.parametrize( + "member, repr_value", + [ + (Colour.RED, "Colour.RED"), + (Colour.GREEN, "Colour.GREEN"), + (Colour.BLUE, "Colour.BLUE"), + ], +) +def test_repr(member: Colour, repr_value: str) -> None: + assert repr(member) == repr_value + + +@pytest.mark.parametrize( + "member, values", + [ + (Colour.RED, ("RED", 1)), + (Colour.GREEN, ("GREEN", 2)), + (Colour.BLUE, ("BLUE", 3)), + (PURPLE, (None, 4)), + ], +) +def test_name_values(member: Colour, values: Tuple[Optional[str], int]) -> None: + assert (member.name, member.value) == values + + +@pytest.mark.parametrize( + "member, input_str", + [ + (Colour.RED, "RED"), + (Colour.GREEN, "GREEN"), + (Colour.BLUE, "BLUE"), + ], +) +def test_from_string(member: Colour, input_str: str) -> None: + assert Colour.from_string(input_str) == member + + +@pytest.mark.parametrize( + "member, input_int", + [ + (Colour.RED, 1), + (Colour.GREEN, 2), + (Colour.BLUE, 3), + (PURPLE, 4), + ], +) +def test_try_value(member: Colour, input_int: int) -> None: + assert Colour.try_value(input_int) == member |