source: utilitiespy/test/tools/enumTest.py@ 1355

Last change on this file since 1355 was 1179, checked in by wouter, 7 weeks ago

#371 added enum base class

File size: 1.0 KB
Line 
1import unittest
2
3from tudelft.utilities.tools.enum import enumValues, enumToString,enum
4
5class SimpleEnum(enum):
6 def val(self) -> str:
7 return "$"
8 @staticmethod
9 def _static_init_():
10 SimpleEnum.P = SimpleEnum()
11 SimpleEnum.Q = SimpleEnum()
12 SimpleEnum.R = SimpleEnum()
13SimpleEnum._static_init_()
14
15class MyEnum(enum):
16 def __init__(self, value:int):
17 self.__value:int
18 self.__value=value
19 def getValue(self) -> int:
20 return self.__value
21 @staticmethod
22 def _static_init_():
23 MyEnum.A = MyEnum(1)
24 MyEnum.B = MyEnum(2)
25 MyEnum.C = MyEnum(3)
26MyEnum._static_init_()
27
28
29
30class EnumTest(unittest.TestCase):
31
32 def test_enumValues_simple(self):
33 self.assertEqual([SimpleEnum.P, SimpleEnum.Q, SimpleEnum.R], enumValues(SimpleEnum))
34 self.assertEqual('P', enumToString(SimpleEnum.P))
35 self.assertEqual('P', str(SimpleEnum.P))
36
37 def test_enumValues_myenum(self):
38 self.assertEqual([MyEnum.A, MyEnum.B,MyEnum.C], enumValues(MyEnum))
39 self.assertEqual('A', enumToString(MyEnum.A))
40 self.assertEqual('A', str(MyEnum.A))
Note: See TracBrowser for help on using the repository browser.