summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2013-09-15 19:34:36 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2013-09-15 19:34:36 (GMT)
commit101e0746d36caa56b93d5c61d8e54938c6edf93b (patch)
tree06f884e13cf1880a0f3a003bc4bb60b0c76a91b3 /Lib/test/test_enum.py
parentdefe7f4c62b992380fdda2833bb46a6505c839f4 (diff)
downloadcpython-101e0746d36caa56b93d5c61d8e54938c6edf93b.zip
cpython-101e0746d36caa56b93d5c61d8e54938c6edf93b.tar.gz
cpython-101e0746d36caa56b93d5c61d8e54938c6edf93b.tar.bz2
Close #18989: enum members will no longer overwrite other attributes, nor be overwritten by them.
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py37
1 files changed, 26 insertions, 11 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 1308003..5d96d6d 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -228,6 +228,32 @@ class TestEnum(unittest.TestCase):
['FALL', 'ANOTHER_SPRING'],
)
+ def test_duplicate_name(self):
+ with self.assertRaises(TypeError):
+ class Color(Enum):
+ red = 1
+ green = 2
+ blue = 3
+ red = 4
+
+ with self.assertRaises(TypeError):
+ class Color(Enum):
+ red = 1
+ green = 2
+ blue = 3
+ def red(self):
+ return 'red'
+
+ with self.assertRaises(TypeError):
+ class Color(Enum):
+ @property
+ def red(self):
+ return 'redder'
+ red = 1
+ green = 2
+ blue = 3
+
+
def test_enum_with_value_name(self):
class Huh(Enum):
name = 1
@@ -618,17 +644,6 @@ class TestEnum(unittest.TestCase):
self.assertIsNot(type(whatever.really), whatever)
self.assertEqual(whatever.this.really(), 'no, not that')
- def test_overwrite_enums(self):
- class Why(Enum):
- question = 1
- answer = 2
- propisition = 3
- def question(self):
- print(42)
- self.assertIsNot(type(Why.question), Why)
- self.assertNotIn(Why.question, Why._member_names_)
- self.assertNotIn(Why.question, Why)
-
def test_wrong_inheritance_order(self):
with self.assertRaises(TypeError):
class Wrong(Enum, str):