diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2013-07-19 00:05:39 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2013-07-19 00:05:39 (GMT) |
commit | f24bb35a69d18a05047399eadc63b4be092aee71 (patch) | |
tree | d2cb70aa9a38166dc38bf54a056f238f43caf747 /Lib/test | |
parent | d85032e25d4f9864ecc694a02a6678b4e6069739 (diff) | |
download | cpython-f24bb35a69d18a05047399eadc63b4be092aee71.zip cpython-f24bb35a69d18a05047399eadc63b4be092aee71.tar.gz cpython-f24bb35a69d18a05047399eadc63b4be092aee71.tar.bz2 |
closes issue18042 -- a `unique` decorator is added to enum.py
The docs also clarify the 'Interesting Example' duplicate-free enum is for
demonstration purposes.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_enum.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 75b2656..2b87c56 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -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() |