]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Additional test for __reduce__.
authorRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 22:50:04 +0000 (22:50 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 22:50:04 +0000 (22:50 +0000)
Lib/test/test_collections.py

index 60d4e0b6b310a7821a382a1239c3e9b95aa398bc..1800becd294f7d95a01e89a8d294bbde66e081f2 100644 (file)
@@ -728,6 +728,14 @@ class TestOrderedDict(unittest.TestCase):
         # '!!python/object/apply:__main__.OrderedDict\n- - [a, 1]\n  - [b, 2]\n'
         self.assert_(all(type(pair)==list for pair in od.__reduce__()[1]))
 
+    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.assertEqual(len(od.__reduce__()), 2)
+        od.x = 10
+        self.assertEqual(len(od.__reduce__()), 3)
+
     def test_repr(self):
         od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])
         self.assertEqual(repr(od),