diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2013-07-20 02:35:56 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2013-07-20 02:35:56 (GMT) |
commit | 2aa2732eafe6ede071dd0206cab831484723483d (patch) | |
tree | 69c78c311984c3807a712b85f63f1140db6f319e /Lib/test/test_enum.py | |
parent | e410f267f1c110d4e9738a0f36e2e27c0365278f (diff) | |
download | cpython-2aa2732eafe6ede071dd0206cab831484723483d.zip cpython-2aa2732eafe6ede071dd0206cab831484723483d.tar.gz cpython-2aa2732eafe6ede071dd0206cab831484723483d.tar.bz2 |
Close #18508 -- fix _value2member_map to always have the member's value
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r-- | Lib/test/test_enum.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 2b87c56..c947182 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -694,6 +694,7 @@ class TestEnum(unittest.TestCase): x = ('the-x', 1) y = ('the-y', 2) + self.assertIs(NEI.__new__, Enum.__new__) self.assertEqual(repr(NEI.x + NEI.y), "NamedInt('(the-x + the-y)', 3)") globals()['NamedInt'] = NamedInt @@ -785,6 +786,7 @@ class TestEnum(unittest.TestCase): [AutoNumber.first, AutoNumber.second, AutoNumber.third], ) self.assertEqual(int(AutoNumber.second), 2) + self.assertEqual(AutoNumber.third.value, 3) self.assertIs(AutoNumber(1), AutoNumber.first) def test_inherited_new_from_enhanced_enum(self): @@ -916,6 +918,22 @@ class TestEnum(unittest.TestCase): self.assertEqual(round(Planet.EARTH.surface_gravity, 2), 9.80) self.assertEqual(Planet.EARTH.value, (5.976e+24, 6.37814e6)) + def test_nonhash_value(self): + class AutoNumberInAList(Enum): + def __new__(cls): + value = [len(cls.__members__) + 1] + obj = object.__new__(cls) + obj._value = value + return obj + class ColorInAList(AutoNumberInAList): + red = () + green = () + blue = () + self.assertEqual(list(ColorInAList), [ColorInAList.red, ColorInAList.green, ColorInAList.blue]) + self.assertEqual(ColorInAList.red.value, [1]) + self.assertEqual(ColorInAList([1]), ColorInAList.red) + + class TestUnique(unittest.TestCase): |