changeset 344:1d73867becbe

Allow tuples in dicts
author Stefano Rivera <stefano@rivera.za.net>
date Fri, 06 Sep 2013 13:38:07 +0200
parents e5f525c87eb9
children 4708e86a9a3c
files nagslang/tests/test_yamlish.py nagslang/yamlish.py
diffstat 2 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/nagslang/tests/test_yamlish.py	Fri Sep 06 12:58:46 2013 +0200
+++ b/nagslang/tests/test_yamlish.py	Fri Sep 06 13:38:07 2013 +0200
@@ -126,6 +126,15 @@
         self.assertEqual(orig['polygons'][1][1],
                          tuple(result['polygons'][1][1]))
 
+    def test_dict_tuples(self):
+        if self.from_pyyaml:
+            raise SkipTest("Can't parse PyYAML tuples")
+        orig = {'tuple': (0, 1)}
+        text = self.dump_s(orig)
+        result = self.load_s(text)
+        self.assertEqual(orig['tuple'],
+                         tuple(result['tuple']))
+
     def test_quoted(self):
         # a literal true is True, but 'true' is a string
         self.roundtrip({'foo': 'true'})
--- a/nagslang/yamlish.py	Fri Sep 06 12:58:46 2013 +0200
+++ b/nagslang/yamlish.py	Fri Sep 06 13:38:07 2013 +0200
@@ -71,10 +71,10 @@
                 output[-1] += ' ' + self._dump_inline(v)
             elif isinstance(v, dict):
                 output += self._dump_block(v, indent + 2)
-            elif isinstance(v, list):
+            elif isinstance(v, (list, tuple)):
                 output += self._dump_block(v, indent)
             else:
-                raise NotImplementedError()
+                raise NotImplementedError("Cannot dump %r", data)
         return output
 
     def _inlineable(self, data):