mirror of
https://github.com/python/cpython.git
synced 2025-12-09 10:37:17 +00:00
Enum: make Flag and IntFlag members iterable (GH-22221)
This commit is contained in:
parent
fc23a9483e
commit
7219e27087
4 changed files with 32 additions and 0 deletions
|
|
@ -2350,6 +2350,12 @@ class TestFlag(unittest.TestCase):
|
|||
self.assertFalse(W in RX)
|
||||
self.assertFalse(X in RW)
|
||||
|
||||
def test_member_iter(self):
|
||||
Color = self.Color
|
||||
self.assertEqual(list(Color.PURPLE), [Color.BLUE, Color.RED])
|
||||
self.assertEqual(list(Color.BLUE), [Color.BLUE])
|
||||
self.assertEqual(list(Color.GREEN), [Color.GREEN])
|
||||
|
||||
def test_auto_number(self):
|
||||
class Color(Flag):
|
||||
red = auto()
|
||||
|
|
@ -2805,6 +2811,12 @@ class TestIntFlag(unittest.TestCase):
|
|||
with self.assertRaises(TypeError):
|
||||
self.assertFalse('test' in RW)
|
||||
|
||||
def test_member_iter(self):
|
||||
Color = self.Color
|
||||
self.assertEqual(list(Color.PURPLE), [Color.BLUE, Color.RED])
|
||||
self.assertEqual(list(Color.BLUE), [Color.BLUE])
|
||||
self.assertEqual(list(Color.GREEN), [Color.GREEN])
|
||||
|
||||
def test_bool(self):
|
||||
Perm = self.Perm
|
||||
for f in Perm:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue