summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-06-16 06:42:36 (GMT)
committerGitHub <noreply@github.com>2022-06-16 06:42:36 (GMT)
commit05b32c1c796d6c80479756ae898f488eac5f4f71 (patch)
treecfeebd93990074a5729b973806c802e047679b46 /Lib/test/test_enum.py
parent8ba1c7f72010dedb80f0794c5f1dd1c97f81ec83 (diff)
downloadcpython-05b32c1c796d6c80479756ae898f488eac5f4f71.zip
cpython-05b32c1c796d6c80479756ae898f488eac5f4f71.tar.gz
cpython-05b32c1c796d6c80479756ae898f488eac5f4f71.tar.bz2
gh-93820: Fix copy() regression in enum.Flag (GH-93876)
GH-26658 introduced a regression in copy / pickle protocol for combined `enum.Flag`s. `copy.copy(re.A | re.I)` would fail with `AttributeError: ASCII|IGNORECASE`. `enum.Flag` now has a `__reduce_ex__()` method that reduces flags by combined value, not by combined name.
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 25b3e2d..28594b0 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -1,3 +1,4 @@
+import copy
import enum
import doctest
import inspect
@@ -734,6 +735,13 @@ class _MinimalOutputTests:
self.assertFormatIsValue('{:5.2}', TE.third)
self.assertFormatIsValue('{:f}', TE.third)
+ def test_copy(self):
+ TE = self.MainEnum
+ copied = copy.copy(TE)
+ self.assertEqual(copied, TE)
+ deep = copy.deepcopy(TE)
+ self.assertEqual(deep, TE)
+
class _FlagTests:
@@ -2654,6 +2662,26 @@ class TestSpecial(unittest.TestCase):
self.assertTrue(isinstance(MyIntFlag.ONE | MyIntFlag.TWO, MyIntFlag), MyIntFlag.ONE | MyIntFlag.TWO)
self.assertTrue(isinstance(MyIntFlag.ONE | 2, MyIntFlag))
+ def test_int_flags_copy(self):
+ class MyIntFlag(IntFlag):
+ ONE = 1
+ TWO = 2
+ FOUR = 4
+
+ flags = MyIntFlag.ONE | MyIntFlag.TWO
+ copied = copy.copy(flags)
+ deep = copy.deepcopy(flags)
+ self.assertEqual(copied, flags)
+ self.assertEqual(deep, flags)
+
+ flags = MyIntFlag.ONE | MyIntFlag.TWO | 8
+ copied = copy.copy(flags)
+ deep = copy.deepcopy(flags)
+ self.assertEqual(copied, flags)
+ self.assertEqual(deep, flags)
+ self.assertEqual(copied.value, 1 | 2 | 8)
+
+
class TestOrder(unittest.TestCase):
"test usage of the `_order_` attribute"