diff Lib/test/test_enum.py @ 85790:ed011b0d7daf

Close #19025: Better error message when trying to delete an Enum member. Also slight code reorg for PEP 8 guidelines.
author Ethan Furman <ethan@stoneleaf.us>
date Sun, 22 Sep 2013 16:18:19 -0700
parents 353ced6ae182
children 516576f5f9dc
line wrap: on
line diff
--- a/Lib/test/test_enum.py	Sun Sep 22 09:33:45 2013 -0400
+++ b/Lib/test/test_enum.py	Sun Sep 22 16:18:19 2013 -0700
@@ -172,6 +172,27 @@
         with self.assertRaises(AttributeError):
             Season.WINTER = 'really cold'
 
+    def test_attribute_deletion(self):
+        class Season(Enum):
+            SPRING = 1
+            SUMMER = 2
+            AUTUMN = 3
+            WINTER = 4
+
+            def spam(cls):
+                pass
+
+        self.assertTrue(hasattr(Season, 'spam'))
+        del Season.spam
+        self.assertFalse(hasattr(Season, 'spam'))
+
+        with self.assertRaises(AttributeError):
+            del Season.SPRING
+        with self.assertRaises(AttributeError):
+            del Season.DRY
+        with self.assertRaises(AttributeError):
+            del Season.SPRING.name
+
     def test_invalid_names(self):
         with self.assertRaises(ValueError):
             class Wrong(Enum):