closes issue18042 -- a unique decorator is added to enum.py

The docs also clarify the 'Interesting Example' duplicate-free enum is for
demonstration purposes.
This commit is contained in:
Ethan Furman 2013-07-18 17:05:39 -07:00
parent d85032e25d
commit f24bb35a69
3 changed files with 115 additions and 29 deletions

View file

@ -2,7 +2,7 @@ import enum
import unittest
from collections import OrderedDict
from pickle import dumps, loads, PicklingError
from enum import Enum, IntEnum
from enum import Enum, IntEnum, unique
# for pickle tests
try:
@ -917,5 +917,38 @@ class TestEnum(unittest.TestCase):
self.assertEqual(Planet.EARTH.value, (5.976e+24, 6.37814e6))
class TestUnique(unittest.TestCase):
def test_unique_clean(self):
@unique
class Clean(Enum):
one = 1
two = 'dos'
tres = 4.0
@unique
class Cleaner(IntEnum):
single = 1
double = 2
triple = 3
def test_unique_dirty(self):
with self.assertRaisesRegex(ValueError, 'tres.*one'):
@unique
class Dirty(Enum):
one = 1
two = 'dos'
tres = 1
with self.assertRaisesRegex(
ValueError,
'double.*single.*turkey.*triple',
):
@unique
class Dirtier(IntEnum):
single = 1
double = 1
triple = 3
turkey = 3
if __name__ == '__main__':
unittest.main()