mirror of
https://github.com/python/cpython.git
synced 2025-08-09 03:19:15 +00:00
[3.12] gh-116040: [Enum] fix by-value calls when second value is falsey (GH-116072) (GH-116476)
e.g. Cardinal(1, 0)
(cherry picked from commit 13ffd4bd9f
)
This commit is contained in:
parent
4efd20e23a
commit
d771729679
3 changed files with 46 additions and 4 deletions
|
@ -3312,6 +3312,40 @@ class TestSpecial(unittest.TestCase):
|
|||
member._value_ = Base(value)
|
||||
return member
|
||||
|
||||
def test_second_tuple_item_is_falsey(self):
|
||||
class Cardinal(Enum):
|
||||
RIGHT = (1, 0)
|
||||
UP = (0, 1)
|
||||
LEFT = (-1, 0)
|
||||
DOWN = (0, -1)
|
||||
self.assertIs(Cardinal(1, 0), Cardinal.RIGHT)
|
||||
self.assertIs(Cardinal(-1, 0), Cardinal.LEFT)
|
||||
|
||||
def test_no_members(self):
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
'has no members',
|
||||
):
|
||||
Enum(7)
|
||||
with self.assertRaisesRegex(
|
||||
TypeError,
|
||||
'has no members',
|
||||
):
|
||||
Flag(7)
|
||||
|
||||
def test_empty_names(self):
|
||||
for nothing, e_type in (
|
||||
('', None),
|
||||
('', int),
|
||||
([], None),
|
||||
([], int),
|
||||
({}, None),
|
||||
({}, int),
|
||||
):
|
||||
empty_enum = Enum('empty_enum', nothing, type=e_type)
|
||||
self.assertEqual(len(empty_enum), 0)
|
||||
self.assertRaises(TypeError, 'has no members', empty_enum, 0)
|
||||
|
||||
|
||||
class TestOrder(unittest.TestCase):
|
||||
"test usage of the `_order_` attribute"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue