Changeset 112:c28f2fc2bb05 for nagslang
- Timestamp:
- Sep 2, 2013, 12:50:30 PM (7 years ago)
- Branch:
- default
- Location:
- nagslang
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
nagslang/tests/test_yamlish.py
r103 r112 1 1 from unittest import TestCase, SkipTest 2 from StringIO import StringIO3 2 4 3 try: … … 7 6 yaml = None # pyflakes:ignore 8 7 9 from nagslang.yamlish import load , dump8 from nagslang.yamlish import load_s, dump_s 10 9 11 10 12 11 class 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) 16 14 17 15 def test_dict_list_1(self): … … 32 30 class TestRoundTrip(TestCase): 33 31 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) 39 35 40 def dump (self, data, f):41 dump(data, f)36 def dump_s(self, data): 37 return dump_s(data) 42 38 43 def load (self, f):44 return load (f)39 def load_s(self, text): 40 return load_s(text) 45 41 46 42 def test_simple_dict(self): … … 80 76 81 77 class TestFromPyYAML(TestRoundTrip): 82 def dump (self, data, f):78 def dump_s(self, data): 83 79 if yaml is None: 84 80 raise SkipTest('yaml module unavailable') 85 yaml.dump(data, f, default_flow_style=False)81 return yaml.dump(data, default_flow_style=False) 86 82 87 83 88 84 class TestToPyYAML(TestRoundTrip): 89 def load (self, f):85 def load_s(self, text): 90 86 if yaml is None: 91 87 raise SkipTest('yaml module unavailable') 92 return yaml.load( f)88 return yaml.load(text) -
nagslang/yamlish.py
r111 r112 22 22 23 23 def load_s(yaml): 24 return Parser().parse(yaml )24 return Parser().parse(yaml.strip()) 25 25 26 26
Note: See TracChangeset
for help on using the changeset viewer.