Changeset 35
- Timestamp:
- 01/29/06 17:33:32 (7 years ago)
- File:
-
- 1 edited
-
trunk/tests/test_emitter.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/test_emitter.py
r23 r35 100 100 ] 101 101 102 COMPLEX_ITEMS = [ 103 _syck.Scalar("foo"), 104 _syck.Scalar("foo", tag='x-private:complex'), 105 _syck.Scalar("foo bar baz", style='fold'), 106 _syck.Scalar("foo bar baz", style='fold', tag='x-private:complex'), 107 _syck.Seq([]), 108 _syck.Seq([], tag='x-private:complex'), 109 _syck.Seq([_syck.Scalar('alpha'), _syck.Scalar('beta'), _syck.Scalar('gamma')]), 110 _syck.Seq([_syck.Scalar('alpha'), _syck.Scalar('beta'), _syck.Scalar('gamma')], tag='x-private:complex'), 111 _syck.Seq([_syck.Scalar('alpha'), _syck.Scalar('beta'), _syck.Scalar('gamma')], inline=True, tag='x-private:complex'), 112 _syck.Map({}), 113 _syck.Map({}, tag='x-private:complex'), 114 _syck.Map([(_syck.Scalar('alpha'), _syck.Scalar('beta')), (_syck.Scalar('gamma'), _syck.Scalar('delta'))], tag='x-private:complex'), 115 _syck.Map([(_syck.Scalar('alpha'), _syck.Scalar('beta')), (_syck.Scalar('gamma'), _syck.Scalar('delta'))], inline=True, tag='x-private:complex'), 116 ] 102 117 103 118 def strip(node, node_to_object=None): … … 115 130 object = tuple(object) 116 131 elif node.kind == 'map': 117 object = {}132 object = [] 118 133 dict_value = dict(node.value) 119 134 for key in dict_value: 120 object[strip(key, node_to_object)] = strip(dict_value[key], node_to_object) 135 object.append((strip(key, node_to_object), strip(dict_value[key], node_to_object))) 136 object.sort() 121 137 node_to_object[node] = object 122 138 return object … … 283 299 284 300 285 #class TestSyckBugWithTrailingSpace(unittest.TestCase): 286 # 287 # def testSyckBugWithTrailingSpace(self): 288 # emitter = _syck.Emitter(StringIO.StringIO()) 289 # emitter.emit(_syck.Scalar('foo ', tag="tag:yaml.org,2002:str")) 290 # parser = _syck.Parser(emitter.output.getvalue()) 291 # self.assertEqual(parser.parse().value, 'foo ') 292 293 301 class TestSyckBugWithTrailingSpace(unittest.TestCase): 302 303 def testSyckBugWithTrailingSpace(self): 304 emitter = _syck.Emitter(StringIO.StringIO()) 305 emitter.emit(_syck.Scalar('foo ', tag="tag:yaml.org,2002:str")) 306 parser = _syck.Parser(emitter.output.getvalue()) 307 self.assertEqual(parser.parse().value, 'foo ') 308 309 310 311 class TestSyckComplexKeyBugs(unittest.TestCase): 312 313 def testEmptyCollectionKeyBug(self): 314 tree1 = _syck.Map({_syck.Map(): _syck.Scalar('foo')}) 315 self._testTree(tree1) 316 tree2 = _syck.Map({_syck.Seq(): _syck.Scalar('foo')}) 317 self._testTree(tree2) 318 319 def testCollectionWithTagKeyBug(self): 320 tree = _syck.Map({_syck.Seq([_syck.Scalar('foo')], tag='x-private:key'): 321 _syck.Scalar('bar')}) 322 self._testTree(tree) 323 324 def testFlowCollectionKeyBug(self): 325 tree = _syck.Map({_syck.Seq([_syck.Scalar('foo')], inline=True): 326 _syck.Scalar('bar')}) 327 self._testTree(tree) 328 329 def testEmptyCollectionWithAliasKeyBug(self): 330 node = _syck.Map() 331 tree = _syck.Map({node: node}) 332 self._testTree(tree) 333 334 def testScalarWithAliasKeyBug(self): 335 node = _syck.Scalar('foo', tag='x-private:bug') 336 tree = _syck.Map({node: node}) 337 self._testTree(tree) 338 339 def _testTree(self, tree): 340 emitter = _syck.Emitter(StringIO.StringIO()) 341 emitter.emit(tree) 342 #print emitter.output.getvalue() 343 parser = _syck.Parser(emitter.output.getvalue()) 344 self.assertEqual(strip(tree), strip(parser.parse())) 345 346 def testSyckBugWithComplexKeys(self): 347 broken = 0 348 for key in COMPLEX_ITEMS: 349 for value in COMPLEX_ITEMS: 350 node = _syck.Map({key: value}) 351 emitter = _syck.Emitter(StringIO.StringIO()) 352 emitter.emit(node) 353 parser = _syck.Parser(emitter.output.getvalue()) 354 self.assertEqual(strip(node), strip(parser.parse())) 355
Note: See TracChangeset
for help on using the changeset viewer.
