Changeset 112:c28f2fc2bb05


Ignore:
Timestamp:
Sep 2, 2013, 12:50:30 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Test with dump_s and load_s

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/tests/test_yamlish.py

    r103 r112  
    11from unittest import TestCase, SkipTest
    2 from StringIO import StringIO
    32
    43try:
     
    76    yaml = None  # pyflakes:ignore
    87
    9 from nagslang.yamlish import load, dump
     8from nagslang.yamlish import load_s, dump_s
    109
    1110
    1211class TestParse(TestCase):
    13     def assertParsesAs(self, yaml, expected):
    14         f = StringIO(yaml.strip())
    15         self.assertEqual(load(f), expected)
     12    def assertParsesAs(self, text, expected):
     13        self.assertEqual(load_s(text.strip()), expected)
    1614
    1715    def test_dict_list_1(self):
     
    3230class TestRoundTrip(TestCase):
    3331    def roundtrip(self, data):
    34         f = StringIO()
    35         self.dump(data, f)
    36         f.seek(0)
    37         print '\n=== Begin ===\n%s\n=== End ===' % f.buf.rstrip()
    38         self.assertEqual(self.load(f), data)
     32        text = self.dump_s(data)
     33        print '\n=== Begin ===\n%s\n=== End ===' % text
     34        self.assertEqual(self.load_s(text), data)
    3935
    40     def dump(self, data, f):
    41         dump(data, f)
     36    def dump_s(self, data):
     37        return dump_s(data)
    4238
    43     def load(self, f):
    44         return load(f)
     39    def load_s(self, text):
     40        return load_s(text)
    4541
    4642    def test_simple_dict(self):
     
    8076
    8177class TestFromPyYAML(TestRoundTrip):
    82     def dump(self, data, f):
     78    def dump_s(self, data):
    8379        if yaml is None:
    8480            raise SkipTest('yaml module unavailable')
    85         yaml.dump(data, f, default_flow_style=False)
     81        return yaml.dump(data, default_flow_style=False)
    8682
    8783
    8884class TestToPyYAML(TestRoundTrip):
    89     def load(self, f):
     85    def load_s(self, text):
    9086        if yaml is None:
    9187            raise SkipTest('yaml module unavailable')
    92         return yaml.load(f)
     88        return yaml.load(text)
  • nagslang/yamlish.py

    r111 r112  
    2222
    2323def load_s(yaml):
    24     return Parser().parse(yaml)
     24    return Parser().parse(yaml.strip())
    2525
    2626
Note: See TracChangeset for help on using the changeset viewer.