summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2015-03-19 01:19:30 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2015-03-19 01:19:30 (GMT)
commit482fe0477e5923f0b8fff16c59052650cf7247cf (patch)
tree0b2ee2281894cda0a745373a8a5df9569a33ec55 /Lib/test/test_enum.py
parentd833779ceaebeb29352488ffddabf5fc2f070364 (diff)
downloadcpython-482fe0477e5923f0b8fff16c59052650cf7247cf.zip
cpython-482fe0477e5923f0b8fff16c59052650cf7247cf.tar.gz
cpython-482fe0477e5923f0b8fff16c59052650cf7247cf.tar.bz2
issue23673
add private method to enum to support replacing global constants with Enum members: - search for candidate constants via supplied filter - create new enum class and members - insert enum class and replace constants with members via supplied module name - replace __reduce_ex__ with function that returns member name, so previous Python versions can unpickle modify IntEnum classes to use new method
Diffstat (limited to 'Lib/test/test_enum.py')
-rw-r--r--Lib/test/test_enum.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index dccaa4f..5db4040 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -581,6 +581,14 @@ class TestEnum(unittest.TestCase):
test_pickle_dump_load(self.assertIs, self.NestedEnum.twigs,
protocol=(4, HIGHEST_PROTOCOL))
+ def test_pickle_by_name(self):
+ class ReplaceGlobalInt(IntEnum):
+ ONE = 1
+ TWO = 2
+ ReplaceGlobalInt.__reduce_ex__ = enum._reduce_ex_by_name
+ for proto in range(HIGHEST_PROTOCOL):
+ self.assertEqual(ReplaceGlobalInt.TWO.__reduce_ex__(proto), 'TWO')
+
def test_exploding_pickle(self):
BadPickle = Enum(
'BadPickle', 'dill sweet bread-n-butter', module=__name__)