]> granicus.if.org Git - python/commitdiff
Add another test.
authorRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 22:38:22 +0000 (22:38 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 3 Mar 2009 22:38:22 +0000 (22:38 +0000)
Lib/test/test_collections.py

index 1e23d5b2b28b00a7ed2ff928df721df1b4e3abc5..60d4e0b6b310a7821a382a1239c3e9b95aa398bc 100644 (file)
@@ -719,6 +719,15 @@ class TestOrderedDict(unittest.TestCase):
             self.assertEquals(len(dup), len(od))
             self.assertEquals(type(dup), type(od))
 
+    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)]
+        od = OrderedDict(pairs)
+        # yaml.dump(od) -->
+        # '!!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_repr(self):
         od = OrderedDict([('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)])
         self.assertEqual(repr(od),