mirror of
https://github.com/python/cpython.git
synced 2025-07-29 14:15:07 +00:00
[3.13] gh-120361: Add nonmember
test with enum flags inside to test_enum
(GH-120364) (#120511)
gh-120361: Add `nonmember` test with enum flags inside to `test_enum` (GH-120364)
* gh-120361: Add `nonmember` test with enum flags inside to `test_enum`
(cherry picked from commit 7fadfd82eb
)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
parent
6e3e112428
commit
da40fa3526
2 changed files with 22 additions and 1 deletions
|
@ -527,7 +527,7 @@ Data Types
|
||||||
|
|
||||||
``Flag`` is the same as :class:`Enum`, but its members support the bitwise
|
``Flag`` is the same as :class:`Enum`, but its members support the bitwise
|
||||||
operators ``&`` (*AND*), ``|`` (*OR*), ``^`` (*XOR*), and ``~`` (*INVERT*);
|
operators ``&`` (*AND*), ``|`` (*OR*), ``^`` (*XOR*), and ``~`` (*INVERT*);
|
||||||
the results of those operators are members of the enumeration.
|
the results of those operations are (aliases of) members of the enumeration.
|
||||||
|
|
||||||
.. method:: __contains__(self, value)
|
.. method:: __contains__(self, value)
|
||||||
|
|
||||||
|
|
|
@ -1495,6 +1495,27 @@ class TestSpecial(unittest.TestCase):
|
||||||
spam = nonmember(SpamEnumIsInner)
|
spam = nonmember(SpamEnumIsInner)
|
||||||
self.assertTrue(SpamEnum.spam is SpamEnumIsInner)
|
self.assertTrue(SpamEnum.spam is SpamEnumIsInner)
|
||||||
|
|
||||||
|
def test_using_members_as_nonmember(self):
|
||||||
|
class Example(Flag):
|
||||||
|
A = 1
|
||||||
|
B = 2
|
||||||
|
ALL = nonmember(A | B)
|
||||||
|
|
||||||
|
self.assertEqual(Example.A.value, 1)
|
||||||
|
self.assertEqual(Example.B.value, 2)
|
||||||
|
self.assertEqual(Example.ALL, 3)
|
||||||
|
self.assertIs(type(Example.ALL), int)
|
||||||
|
|
||||||
|
class Example(Flag):
|
||||||
|
A = auto()
|
||||||
|
B = auto()
|
||||||
|
ALL = nonmember(A | B)
|
||||||
|
|
||||||
|
self.assertEqual(Example.A.value, 1)
|
||||||
|
self.assertEqual(Example.B.value, 2)
|
||||||
|
self.assertEqual(Example.ALL, 3)
|
||||||
|
self.assertIs(type(Example.ALL), int)
|
||||||
|
|
||||||
def test_nested_classes_in_enum_with_member(self):
|
def test_nested_classes_in_enum_with_member(self):
|
||||||
"""Support locally-defined nested classes."""
|
"""Support locally-defined nested classes."""
|
||||||
class Outer(Enum):
|
class Outer(Enum):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue