mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-44242: [Enum] improve error messages (GH-26669)
(cherry picked from commit c956734d7a
)
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
This commit is contained in:
parent
e6d28a1a6a
commit
0a186b1ec1
2 changed files with 30 additions and 19 deletions
|
@ -2158,9 +2158,6 @@ class TestEnum(unittest.TestCase):
|
|||
self._valid = True
|
||||
@classmethod
|
||||
def _missing_(cls, value):
|
||||
# encountered an unknown value!
|
||||
# Luckily I'm a LenientStrEnum, so I won't crash just yet.
|
||||
# You might want to add a new case though.
|
||||
unknown = cls._member_type_.__new__(cls, value)
|
||||
unknown._valid = False
|
||||
unknown._name_ = value.upper()
|
||||
|
@ -3586,7 +3583,7 @@ class TestVerify(unittest.TestCase):
|
|||
self.assertEqual(Bizarre.d.value, 6)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"invalid Flag 'Bizarre': 'b' is missing named flags for values 1, 2; 'd' is missing a named flag for value 2",
|
||||
"invalid Flag 'Bizarre': aliases b and d are missing combined values of 0x3 .use `enum.show_flag_values.value.` for details.",
|
||||
):
|
||||
@verify(NAMED_FLAGS)
|
||||
class Bizarre(Flag):
|
||||
|
@ -3594,6 +3591,7 @@ class TestVerify(unittest.TestCase):
|
|||
c = 4
|
||||
d = 6
|
||||
#
|
||||
self.assertEqual(enum.show_flag_values(3), [1, 2])
|
||||
class Bizarre(IntFlag):
|
||||
b = 3
|
||||
c = 4
|
||||
|
@ -3604,13 +3602,13 @@ class TestVerify(unittest.TestCase):
|
|||
self.assertEqual(Bizarre.d.value, 6)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"invalid Flag 'Bizarre': 'b' is missing named flags for values 1, 2; 'd' is missing a named flag for value 2",
|
||||
"invalid Flag 'Bizarre': alias d is missing value 0x2 .use `enum.show_flag_values.value.` for details.",
|
||||
):
|
||||
@verify(NAMED_FLAGS)
|
||||
class Bizarre(IntFlag):
|
||||
b = 3
|
||||
c = 4
|
||||
d = 6
|
||||
self.assertEqual(enum.show_flag_values(2), [2])
|
||||
|
||||
def test_unique_clean(self):
|
||||
@verify(UNIQUE)
|
||||
|
@ -3877,7 +3875,7 @@ class TestStdLib(unittest.TestCase):
|
|||
|
||||
class MiscTestCase(unittest.TestCase):
|
||||
def test__all__(self):
|
||||
support.check__all__(self, enum, not_exported={'bin'})
|
||||
support.check__all__(self, enum, not_exported={'bin', 'show_flag_values'})
|
||||
|
||||
|
||||
# These are unordered here on purpose to ensure that declaration order
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue