mirror of
https://github.com/python/cpython.git
synced 2025-08-29 21:25:01 +00:00
Close #19025: Better error message when trying to delete an Enum member.
Also slight code reorg for PEP 8 guidelines.
This commit is contained in:
parent
0c47f34385
commit
64a9972b40
2 changed files with 33 additions and 2 deletions
|
@ -172,6 +172,27 @@ class TestEnum(unittest.TestCase):
|
|||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue