summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2023-03-31 20:52:31 (GMT)
committerGitHub <noreply@github.com>2023-03-31 20:52:31 (GMT)
commit2a4d8c0a9e88f45047da640ce5a92b304d2d39b1 (patch)
tree6c519d3b27d6424429b09196e02ad442dff5649c /Lib/test/test_enum.py
parentdfc4c95762f417e84dcb21dbbe6399ab7b7cef19 (diff)
downloadcpython-2a4d8c0a9e88f45047da640ce5a92b304d2d39b1.zip
cpython-2a4d8c0a9e88f45047da640ce5a92b304d2d39b1.tar.gz
cpython-2a4d8c0a9e88f45047da640ce5a92b304d2d39b1.tar.bz2
gh-102549: [Enum] fail enum creation when data type raises in __init__ (GH-103149)
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index bea1954..ee52806 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -2916,6 +2916,26 @@ class TestSpecial(unittest.TestCase):
self.assertEqual(FlagFromChar.a, 158456325028528675187087900672)
self.assertEqual(FlagFromChar.a|1, 158456325028528675187087900673)
+ def test_init_exception(self):
+ class Base:
+ def __init__(self, x):
+ raise ValueError("I don't like", x)
+ with self.assertRaises(TypeError):
+ class MyEnum(Base, enum.Enum):
+ A = 'a'
+ def __init__(self, y):
+ self.y = y
+ with self.assertRaises(ValueError):
+ class MyEnum(Base, enum.Enum):
+ A = 'a'
+ def __init__(self, y):
+ self.y = y
+ def __new__(cls, value):
+ member = Base.__new__(cls)
+ member._value_ = Base(value)
+ return member
+
+
class TestOrder(unittest.TestCase):
"test usage of the `_order_` attribute"