Ignore:
Timestamp:
09/02/13 00:18:50 (8 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Amend:
63393330313363613231316330613166373636623937663033313537396430393532623165393632
Message:

Dump our YAML subset too

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/tests/test_level_serializer.py

    r89 r90  
    1 from unittest import TestCase
     1from unittest import TestCase, SkipTest
    22from StringIO import StringIO
     3
     4try:
     5    import yaml
     6except ImportError:
     7    yaml = None  # pyflakes:ignore
    38
    49from nagslang.level_serializer import load, dump
    510
    611
    7 class TestSimple(TestCase):
     12class TestRoundTrip(TestCase):
    813    def roundtrip(self, data):
    914        f = StringIO()
     15        self.dump(data, f)
     16        f.seek(0)
     17        print '\n=== Begin ===\n%s\n=== End ===' % f.buf.rstrip()
     18        self.assertEqual(self.load(f), data)
     19
     20    def dump(self, data, f):
    1021        dump(data, f)
    11         f.seek(0)
    12         #print '\n== Begin ==\n%s== End ==' % f.buf
    13         self.assertEqual(load(f), data)
     22
     23    def load(self, f):
     24        return load(f)
    1425
    1526    def test_simple_dict(self):
     
    4657            ],
    4758        })
     59
     60
     61class TestFromPyYAML(TestRoundTrip):
     62    def dump(self, data, f):
     63        if yaml is None:
     64            raise SkipTest('yaml module unavailable')
     65        yaml.dump(data, f, default_flow_style=False)
     66
     67
     68class TestToPyYAML(TestRoundTrip):
     69    def load(self, f):
     70        if yaml is None:
     71            raise SkipTest('yaml module unavailable')
     72        return yaml.load(f)
Note: See TracChangeset for help on using the changeset viewer.