-
Notifications
You must be signed in to change notification settings - Fork 276
/
Copy pathenum_extend.py
50 lines (40 loc) · 1.2 KB
/
enum_extend.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest
from enum import Enum
class EnumExtend(unittest.TestCase):
def test_extending(self):
class Color(Enum):
red = 1
green = 2
blue = 3
# TypeError: Cannot extend enumerations
with self.assertRaises(TypeError):
class MoreColor(Color):
cyan = 4
magenta = 5
yellow = 6
def test_extending2(self):
class Shade(Enum):
def shade(self):
print(self.name)
class Color(Shade):
red = 1
green = 2
blue = 3
with self.assertRaises(TypeError):
class MoreColor(Color):
cyan = 4
magenta = 5
yellow = 6
def test_extending3(self):
class Shade(Enum):
def shade(self):
return self.name
class Color(Shade):
def hex(self):
return '%s nice!' % self.value
class MoreColor(Color):
cyan = 4
magenta = 5
yellow = 6
self.assertEqual(MoreColor.magenta.shade(), 'magenta')
self.assertEqual(MoreColor.magenta.hex(), '5 nice!')