示例#1
0
 def testParser(self):
     thread = MyThread(N)
     thread.start()
     syck.parse(DATA_FOR_PARSER)
     thread.stop()
     #print "testParser value:", thread.value
     self.assert_(thread.done())
示例#2
0
 def testNonsense(self):
     class MyFile1:
         def read(self, max_length):
             return ' '*(max_length+1)
     class MyFile2:
         def read(self, max_length):
             return None
     self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
     self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
     self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
     self.assertRaises(TypeError, lambda: syck.load(MyFile2()))
示例#3
0
 def testNonsense(self):
     class MyFile1:
         def read(self, max_length):
             return ' '*(max_length+1)
     class MyFile2:
         def read(self, max_length):
             return None
     self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
     self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
     self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
     self.assertRaises(TypeError, lambda: syck.load(MyFile2()))
示例#4
0
class TestValuesAndSources(test_parser.TestValuesAndSources):

    def testValues1(self):
        self._testValues(test_parser.COMPARE1)

    def testValues2(self):
        self._testValues(test_parser.COMPARE2)

    def testValues3(self):
        self._testValues(test_parser.COMPARE3)

    def testFileValues1(self):
        self._testFileValues(test_parser.COMPARE1)

    def testFileValues2(self):
        self._testFileValues(test_parser.COMPARE2)

    def testFileValues3(self):
        self._testFileValues(test_parser.COMPARE3)

    def testNonsense(self):
        class MyFile1:
            def read(self, max_length):
                return ' '*(max_length+1)
        class MyFile2:
            def read(self, max_length):
                return None
        self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
        self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
        self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
        self.assertRaises(TypeError, lambda: syck.load(MyFile2()))

    def _testValues(self, (source, structure)):
        self.assertEqualStructure(syck.parse(source), structure)
        self.assertEqual(syck.load(source), structure)
示例#5
0
 def testBuggyNodesReduce(self):
     object = syck.load(BUGGY_NODES)
     nodes = syck.parse(BUGGY_NODES)
     output = syck.dump(nodes)
     #print output
     nodes2 = syck.load(output)
     output2 = syck.emit(nodes2)
     object2 = syck.load(output2)
     self.assertEqual(object, object2)
示例#6
0
 def testDumpUnicode(self):
     for string, tag in UNICODE_STRINGS:
         #print string
         document = syck.dump(string)
         #print document
         new_tag = syck.parse(document).tag
         new_string = syck.load(document)
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
         self.assertEqual(tag, new_tag)
示例#7
0
 def testDumpUnicode(self):
     for string, tag in UNICODE_STRINGS:
         #print string
         document = syck.dump(string)
         #print document
         new_tag = syck.parse(document).tag
         new_string = syck.load(document)
         self.assertEqual(string, new_string)
         self.assertEqual(type(string), type(new_string))
         self.assertEqual(tag, new_tag)
示例#8
0
 def testAliasesParsing(self):
     node = syck.parse(ALIASES)
     values = node.value.values()
     self.assert_(values[0] is values[1])
示例#9
0
            def read(self, max_length):
                return None
        self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
        self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
        self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
        self.assertRaises(TypeError, lambda: syck.load(MyFile2()))

    def _testValues(self, (source, structure)):
        self.assertEqualStructure(syck.parse(source), structure)
        self.assertEqual(syck.load(source), structure)

    def _testFileValues(self, (source, structure)):
        tempfile = os.tmpfile()
        tempfile.write(source)
        tempfile.seek(0)
        self.assertEqualStructure(syck.parse(tempfile), structure)
        tempfile.seek(0)
        self.assertEqual(syck.load(tempfile), structure)
        tempfile.seek(0)

class TestImplicitScalars(unittest.TestCase):


    def testBinary(self):
        self.assertEqual(syck.load(BINARY), [ARROW, ARROW])

    def testBoolean(self):
        # Syck does not recognize 'y'.
        #self.assertEqual(syck.load('- y\n- NO\n- True\n- on\n'), [True, False, True, True])
        self.assertEqual(syck.load('- yes\n- NO\n- True\n- on\n'), [True, False, True, True])
示例#10
0
 def testAliasesParsing(self):
     node = syck.parse(ALIASES)
     values = node.value.values()
     self.assert_(values[0] is values[1])
示例#11
0
            def read(self, max_length):
                return None
        self.assertRaises(ValueError, lambda: syck.parse(MyFile1()))
        self.assertRaises(ValueError, lambda: syck.load(MyFile1()))
        self.assertRaises(TypeError, lambda: syck.parse(MyFile2()))
        self.assertRaises(TypeError, lambda: syck.load(MyFile2()))

    def _testValues(self, (source, structure)):
        self.assertEqualStructure(syck.parse(source), structure)
        self.assertEqual(syck.load(source), structure)

    def _testFileValues(self, (source, structure)):
        tempfile = os.tmpfile()
        tempfile.write(source)
        tempfile.seek(0)
        self.assertEqualStructure(syck.parse(tempfile), structure)
        tempfile.seek(0)
        self.assertEqual(syck.load(tempfile), structure)
        tempfile.seek(0)

class TestImplicitScalars(unittest.TestCase):


    def testBinary(self):
        self.assertEqual(syck.load(BINARY), [ARROW, ARROW])

    def testBoolean(self):
        # Syck does not recognize 'y'.
        #self.assertEqual(syck.load('- y\n- NO\n- True\n- on\n'), [True, False, True, True])
        self.assertEqual(syck.load('- yes\n- NO\n- True\n- on\n'), [True, False, True, True])
示例#12
0
 def testOddAliases(self):
     document = syck.parse(syck.dump(ODD_ALIASES))
     for group in document.value:
         for item in group.value[1:]:
             self.assert_(item is not group.value[0])
示例#13
0
 def testStringDocument(self):
     source = syck.emit(test_emitter.EXAMPLE)
     node = syck.parse(source)
     self.assertEqual(test_emitter.strip(test_emitter.EXAMPLE),
             test_emitter.strip(node))