Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(156309)

Unified Diff: Lib/test/test_collections.py

Issue 17900: Recursive OrderedDict pickling (Closed)
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/collections/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_collections.py Sat Nov 01 07:40:22 2014 -0700
+++ b/Lib/test/test_collections.py Sun Nov 02 16:51:38 2014 +0200
@@ -1490,24 +1490,33 @@ class TestOrderedDict(unittest.TestCase)
def test_yaml_linkage(self):
# Verify that __reduce__ is setup in a way that supports PyYAML's dump() feature.
# In yaml, lists are native but tuples are not.
- pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
+ pairs = [['c', 1], ['b', 2], ['a', 3], ['d', 4], ['e', 5], ['f', 6]]
od = OrderedDict(pairs)
# yaml.dump(od) -->
# '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n - [b, 2]\n'
- self.assertTrue(all(type(pair)==list for pair in od.__reduce__()[1]))
+ for rv in (od.__reduce__(), od.__reduce_ex__(2)):
+ self.assertEqual(len(rv), 2)
+ self.assertEqual(len(rv[1]), 1)
+ for i, pair in enumerate(rv[1][0]):
+ self.assertEqual(type(pair), list, (i, pair))
+ self.assertEqual(rv[1][0], pairs)
def test_reduce_not_too_fat(self):
# 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.assertIsNone(od.__reduce__()[2])
- od.x = 10
- self.assertIsNotNone(od.__reduce__()[2])
+ for proto in range(pickle.HIGHEST_PROTOCOL + 1):
+ od = OrderedDict(pairs)
+ rv = od.__reduce_ex__(proto)
+ if len(rv) > 2:
+ self.assertIsNone(rv[2])
+ od.x = 10
+ rv = od.__reduce_ex__(proto)
+ self.assertIsNotNone(rv[2])
def test_pickle_recursive(self):
od = OrderedDict()
od[1] = od
- for proto in range(-1, pickle.HIGHEST_PROTOCOL + 1):
+ for proto in range(3, pickle.HIGHEST_PROTOCOL + 1):
dup = pickle.loads(pickle.dumps(od, proto))
self.assertIsNot(dup, od)
self.assertEqual(list(dup.keys()), [1])
« no previous file with comments | « Lib/collections/__init__.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+