mirror of
https://github.com/python/cpython.git
synced 2025-07-12 13:55:34 +00:00
bpo-46262: [Enum] test error path in Flag._missing_
(GH-30408)
add tests that exercise the `_missing_` error path for `Flag` and `IntFlag` Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
31e43cbe5f
commit
91bc6f9615
2 changed files with 27 additions and 0 deletions
|
@ -3414,6 +3414,19 @@ class TestFlag(unittest.TestCase):
|
|||
self.assertFalse(NeverEnum.__dict__.get('_test1', False))
|
||||
self.assertFalse(NeverEnum.__dict__.get('_test2', False))
|
||||
|
||||
def test_default_missing(self):
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"'RED' is not a valid TestFlag.Color",
|
||||
) as ctx:
|
||||
self.Color('RED')
|
||||
self.assertIs(ctx.exception.__context__, None)
|
||||
|
||||
P = Flag('P', 'X Y')
|
||||
with self.assertRaisesRegex(ValueError, "'X' is not a valid P") as ctx:
|
||||
P('X')
|
||||
self.assertIs(ctx.exception.__context__, None)
|
||||
|
||||
|
||||
class TestIntFlag(unittest.TestCase):
|
||||
"""Tests of the IntFlags."""
|
||||
|
@ -3975,6 +3988,19 @@ class TestIntFlag(unittest.TestCase):
|
|||
'at least one thread failed while creating composite members')
|
||||
self.assertEqual(256, len(seen), 'too many composite members created')
|
||||
|
||||
def test_default_missing(self):
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"'RED' is not a valid TestIntFlag.Color",
|
||||
) as ctx:
|
||||
self.Color('RED')
|
||||
self.assertIs(ctx.exception.__context__, None)
|
||||
|
||||
P = IntFlag('P', 'X Y')
|
||||
with self.assertRaisesRegex(ValueError, "'X' is not a valid P") as ctx:
|
||||
P('X')
|
||||
self.assertIs(ctx.exception.__context__, None)
|
||||
|
||||
|
||||
class TestEmptyAndNonLatinStrings(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue