Mercurial > nagslang
diff nagslang/tests/test_level_serializer.py @ 89:102043902451
Simple (subset of) YAML parser
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Mon, 02 Sep 2013 00:55:59 +0200 |
parents | |
children | a8d83de5b460 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nagslang/tests/test_level_serializer.py Mon Sep 02 00:55:59 2013 +0200 @@ -0,0 +1,47 @@ +from unittest import TestCase +from StringIO import StringIO + +from nagslang.level_serializer import load, dump + + +class TestSimple(TestCase): + def roundtrip(self, data): + f = StringIO() + dump(data, f) + f.seek(0) + #print '\n== Begin ==\n%s== End ==' % f.buf + self.assertEqual(load(f), data) + + def test_simple_dict(self): + self.roundtrip({'foo': 'bar'}) + + def test_dict_of_dicts(self): + self.roundtrip({'foo': {'bar': 'baz'}}) + + def test_dict_tree(self): + self.roundtrip({ + 'foo': { + 'bar': { + 'baz': 'qux' + }, + 'quux': 'corge', + } + }) + + def test_dict_list(self): + self.roundtrip({ + 'foo': ['bar', 'baz'], + }) + + def test_nested_lists(self): + self.roundtrip({ + 'foo': [['bar', 'baz', 'qux'], 'quux'], + }) + + def test_list_of_dicts(self): + self.roundtrip({ + 'foo': [ + {'bar': 'baz'}, + {'qux': 'quux'}, + ], + })