import unittest from tudelft.utilities.tools.enum import enumValues, enumToString,enum class SimpleEnum(enum): def val(self) -> str: return "$" @staticmethod def _static_init_(): SimpleEnum.P = SimpleEnum() SimpleEnum.Q = SimpleEnum() SimpleEnum.R = SimpleEnum() SimpleEnum._static_init_() class MyEnum(enum): def __init__(self, value:int): self.__value:int self.__value=value def getValue(self) -> int: return self.__value @staticmethod def _static_init_(): MyEnum.A = MyEnum(1) MyEnum.B = MyEnum(2) MyEnum.C = MyEnum(3) MyEnum._static_init_() class EnumTest(unittest.TestCase): def test_enumValues_simple(self): self.assertEqual([SimpleEnum.P, SimpleEnum.Q, SimpleEnum.R], enumValues(SimpleEnum)) self.assertEqual('P', enumToString(SimpleEnum.P)) self.assertEqual('P', str(SimpleEnum.P)) def test_enumValues_myenum(self): self.assertEqual([MyEnum.A, MyEnum.B,MyEnum.C], enumValues(MyEnum)) self.assertEqual('A', enumToString(MyEnum.A)) self.assertEqual('A', str(MyEnum.A))