mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
[3.11] gh-93820: Pickle enum.Flag by name (GH-93891). (GH-94288)
(cherry picked from commit 536985814a
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
5ce819f3c5
commit
1b27ec5ac6
3 changed files with 58 additions and 3 deletions
|
@ -66,10 +66,27 @@ try:
|
|||
class FlagStooges(Flag):
|
||||
LARRY = 1
|
||||
CURLY = 2
|
||||
MOE = 3
|
||||
MOE = 4
|
||||
except Exception as exc:
|
||||
FlagStooges = exc
|
||||
|
||||
class FlagStoogesWithZero(Flag):
|
||||
NOFLAG = 0
|
||||
LARRY = 1
|
||||
CURLY = 2
|
||||
MOE = 4
|
||||
|
||||
class IntFlagStooges(IntFlag):
|
||||
LARRY = 1
|
||||
CURLY = 2
|
||||
MOE = 4
|
||||
|
||||
class IntFlagStoogesWithZero(IntFlag):
|
||||
NOFLAG = 0
|
||||
LARRY = 1
|
||||
CURLY = 2
|
||||
MOE = 4
|
||||
|
||||
# for pickle test and subclass tests
|
||||
class Name(StrEnum):
|
||||
BDFL = 'Guido van Rossum'
|
||||
|
@ -2964,9 +2981,32 @@ class OldTestFlag(unittest.TestCase):
|
|||
def test_pickle(self):
|
||||
if isinstance(FlagStooges, Exception):
|
||||
raise FlagStooges
|
||||
test_pickle_dump_load(self.assertIs, FlagStooges.CURLY|FlagStooges.MOE)
|
||||
test_pickle_dump_load(self.assertIs, FlagStooges.CURLY)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
FlagStooges.CURLY|FlagStooges.MOE)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
FlagStooges.CURLY&~FlagStooges.CURLY)
|
||||
test_pickle_dump_load(self.assertIs, FlagStooges)
|
||||
|
||||
test_pickle_dump_load(self.assertIs, FlagStoogesWithZero.CURLY)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
FlagStoogesWithZero.CURLY|FlagStoogesWithZero.MOE)
|
||||
test_pickle_dump_load(self.assertIs, FlagStoogesWithZero.NOFLAG)
|
||||
|
||||
test_pickle_dump_load(self.assertIs, IntFlagStooges.CURLY)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
IntFlagStooges.CURLY|IntFlagStooges.MOE)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
IntFlagStooges.CURLY|IntFlagStooges.MOE|0x30)
|
||||
test_pickle_dump_load(self.assertEqual, IntFlagStooges(0))
|
||||
test_pickle_dump_load(self.assertEqual, IntFlagStooges(0x30))
|
||||
test_pickle_dump_load(self.assertIs, IntFlagStooges)
|
||||
|
||||
test_pickle_dump_load(self.assertIs, IntFlagStoogesWithZero.CURLY)
|
||||
test_pickle_dump_load(self.assertEqual,
|
||||
IntFlagStoogesWithZero.CURLY|IntFlagStoogesWithZero.MOE)
|
||||
test_pickle_dump_load(self.assertIs, IntFlagStoogesWithZero.NOFLAG)
|
||||
|
||||
@unittest.skipIf(
|
||||
python_version >= (3, 12),
|
||||
'__contains__ now returns True/False for all inputs',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue