diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-05-21 09:47:57 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-05-21 09:47:57 (GMT) |
commit | 3ee6dabf5b2bcfe5aa27a6db4f7adb7d7f33f8d6 (patch) | |
tree | ad4d88662f6f20d28f16a6ee262a29a8d7ff62ad /Lib/test/test_collections.py | |
parent | b10c71daa2099c450101e5854fd693a405bec49c (diff) | |
download | cpython-3ee6dabf5b2bcfe5aa27a6db4f7adb7d7f33f8d6.zip cpython-3ee6dabf5b2bcfe5aa27a6db4f7adb7d7f33f8d6.tar.gz cpython-3ee6dabf5b2bcfe5aa27a6db4f7adb7d7f33f8d6.tar.bz2 |
Issue #17900: Allowed pickling of recursive OrderedDicts. Decreased pickled
size and pickling time.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 8033031..8f379ef 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -1245,9 +1245,18 @@ class TestOrderedDict(unittest.TestCase): # do not save instance dictionary if not needed pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] od = OrderedDict(pairs) - self.assertEqual(len(od.__reduce__()), 2) + self.assertIsNone(od.__reduce__()[2]) od.x = 10 - self.assertEqual(len(od.__reduce__()), 3) + self.assertIsNotNone(od.__reduce__()[2]) + + def test_pickle_recursive(self): + od = OrderedDict() + od[1] = od + for proto in range(-1, pickle.HIGHEST_PROTOCOL + 1): + dup = pickle.loads(pickle.dumps(od, proto)) + self.assertIsNot(dup, od) + self.assertEqual(list(dup.keys()), [1]) + self.assertIs(dup[1], dup) def test_repr(self): od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]) |