示例#1
0
 def test_DifferentStructureXML1_Text(self):
     tree1 = "<a><a>a</a>a</a>"
     tree2 = "<d>a</d>"
     
     expected = '<e>a<a>a</a>a</e>'
     
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expected), "Expected:\n%s\nGot:\n%s\n" % (expected, result))
示例#2
0
 def test_SimpleXML4_TextLeadingAndTrailing(self):
     tree1 = "<a>a<a/>a</a>"
     tree2 = "<d>a<a/>a</d>"
     
     expected = '<e>C<b/>C</e>'
     
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expected), "Expected:\n%s\nGot:\n%s\n" % (expected, result))
示例#3
0
 def test_SimpleXML3_DifferentChildren(self):
     tree1 = "<a><b id='1'/></a>"
     tree2 = "<d><e id='a'><a/></e></d>"
     
     expected = '<e><g id="2"><a/></g></e>'
     
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expected), "Expected:\n%s\nGot:\n%s\n" % (expected, result))
示例#4
0
 def test_RootWithText(self):
     expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test9', 'expected.xml')))
                                             
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test9', 'TreeTestFile_add15.xml')))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test9', 'TreeTestFile_add16.xml')))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected \n%s \ngot \n%s" % (expectedtree, result))
         
     #test commutativity
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected \n%s \ngot \n%s" % (expectedtree, result))
示例#5
0
 def test_ComplexTrees_TrailingUnitsInResult(self):
     expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test7', 'expected.xml')))
     
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test7', 'TreeTestFile_add11.xml')))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test7', 'TreeTestFile_add12.xml')))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, got %s" % (expectedtree, result))
     
     #test commutativity)
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, \ngot %s" % (expectedtree, result))
示例#6
0
 def test_ComplexTrees_SeveralUnitsInOperand(self):
     expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test6', 'expected.xml')))
     
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test6', 'TreeTestFile_add9.xml')))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test6', 'TreeTestFile_add10.xml')))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, got %s" % (expectedtree, result))
                     
     #test commutativity     
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, got %s" % (expectedtree, result))
示例#7
0
 def test_ComplexTrees_UnequalStructures(self):
     expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test5', 'expected.xml')))
     
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test5', 'TreeTestFile_add7.xml')))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test5', 'TreeTestFile_add8.xml')))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, got %s" % (expectedtree, result))
     
     #test commutativity     
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected %s, \ngot %s" % (expectedtree, result))
示例#8
0
 def test_SimpleTrees_UnequalStructures(self):
     expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test4', 'expected.xml')))
     
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test4', 'TreeTestFile_add5.xml')))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test4', 'TreeTestFile_add6.xml')))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Add failed, created incorrect tree")
     
     #test commutativity    
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Add failed, created incorrect tree")
示例#9
0
    def test_AddUnit(self):
        expectedtree = ''.join(open(os.path.join(self.testfilesdir, 'test3', 'expected.xml'), 'r'))
        
        tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test3', 'TreeTestFile_add3.xml')))
        tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test3', 'TreeTestFile_unit.xml')))
        result = Operations.add(tree1, tree2)
        self.assertTrue(Operations.equal(result, expectedtree), "Add failed, created incorrect tree")
 
        #test commutativity
        result = Operations.add(tree2, tree1)
        self.assertTrue(Operations.equal(result, expectedtree), "Add failed, created incorrect tree")
示例#10
0
 def test_SimpleTrees_EqualStructures(self):
 
     expectedtree  = ''.join(open(os.path.join(self.testfilesdir, 'test1', 'expected_add1.xml'), 'r'))
     
     tree1 = ''.join(open(os.path.join(self.testfilesdir, 'test1', 'TreeTestFile_add1.xml'), 'r'))
     tree2 = ''.join(open(os.path.join(self.testfilesdir, 'test1', 'TreeTestFile_add2.xml'), 'r'))
     result = Operations.add(tree1, tree2)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected: \n%s\nGot: \n%s\n" % (expectedtree, result))
                
     #test commutativity    
     result = Operations.add(tree2, tree1)
     self.assertTrue(Operations.equal(result, expectedtree), "Expected: \n%s\nGot: \n%s\n" % (expectedtree, result))
示例#11
0
 def test_2(self):
     testfile = os.path.join(self.testfilesdir, 'test1', 'test1.xml')
     string = ''.join(open(testfile, 'r'))
     ordering = Operations.getOrdering(string)
     
     expected = [
                  [0],
                  [0, 0],
                  [0, 0, 0],
                  [0, 0, 1],
                  [0, 1],
                  [0, 2],
                  [0, 2, 0],
                  [0, 2, 1], 
                  [0, 2, 2], 
                  [0, 2, 3],
                  [0, 2, 4],
                  [0, 2, 4, 0],
                  [0, 2, 4, 0, 0],
                  [0, 2, 4, 0, 1],
                  [0, 2, 4, 1],
                  [0, 2, 5], 
                  [0, 3],
                  [1]
                 ]  
     
     self.assertEqual(ordering, expected, "expected: \n%s\nGot: \n%s\n" % (str(expected), str(ordering)))
示例#12
0
 def test_SimpleXML_Equal(self):
     tree1 = "<xml><a/></xml>"
     tree2 = "<xml><a/></xml>"
     
     result = Operations.equal(tree1, tree2)
     self.assertTrue(result, 'equal() returned %s, expected True' % str(result))