diff options
author | Ethan Furman <ethan@stoneleaf.us> | 2015-03-19 00:27:57 (GMT) |
---|---|---|
committer | Ethan Furman <ethan@stoneleaf.us> | 2015-03-19 00:27:57 (GMT) |
commit | 24e837f23126eab7486a77f3cb51b982226adb70 (patch) | |
tree | f73fe9872045e331ab42f6c34b2109620d9347f7 /Lib/test | |
parent | 8eef6a9ad04f6f81190f44ae3ded427e4083baa2 (diff) | |
download | cpython-24e837f23126eab7486a77f3cb51b982226adb70.zip cpython-24e837f23126eab7486a77f3cb51b982226adb70.tar.gz cpython-24e837f23126eab7486a77f3cb51b982226adb70.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')
-rw-r--r-- | Lib/test/test_enum.py | 8 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 5 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 7d172c8..51d9deb 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__) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index cf45b73..d43e56d 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1377,6 +1377,11 @@ class GeneralModuleTests(unittest.TestCase): with sock: for protocol in range(pickle.HIGHEST_PROTOCOL + 1): self.assertRaises(TypeError, pickle.dumps, sock, protocol) + for protocol in range(pickle.HIGHEST_PROTOCOL + 1): + family = pickle.loads(pickle.dumps(socket.AF_INET, protocol)) + self.assertEqual(family, socket.AF_INET) + type = pickle.loads(pickle.dumps(socket.SOCK_STREAM, protocol)) + self.assertEqual(type, socket.SOCK_STREAM) def test_listen_backlog(self): for backlog in 0, -1: |