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

Last change on this file since 1271 was 1179, checked in by wouter, 3 weeks ago

#371 added enum base class

File size: 1.0 KB
RevLine 
[1176]1import unittest
2
[1179]3from tudelft.utilities.tools.enum import enumValues, enumToString,enum
[1176]4
[1179]5class SimpleEnum(enum):
[1176]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
[1179]15class MyEnum(enum):
[1176]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))
[1179]35 self.assertEqual('P', str(SimpleEnum.P))
[1176]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))
[1179]40 self.assertEqual('A', str(MyEnum.A))
Note: See TracBrowser for help on using the repository browser.