def test_compare_helper_3 (self) : """ finds a match deep into the tree w/ siblings """ tag_list = [] #These are for the main tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("<A>") tag_list.append("<B>") tag_list.append("</B>") tag_list.append("<C>") tag_list.append("</C>") tag_list.append("</A>") tag_list.append("</Inner>") tag_list.append("</Outer>") #these are for the key tree tag_list.append("<A>") tag_list.append("<C>") tag_list.append("<F>") tag_list.append("</F>") tag_list.append("</C>") tag_list.append("</A>") tree_list_1C = [] xml_populate_trees(tag_list, tree_list_1C) result = xml_compare_helper(tree_list_1C[0], tree_list_1C[1]) self.assert_(result == False)
def test_compare_helper_2 (self) : """ compares 2 identical trees and returns True """ tag_list = [] #These are for the main tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("</Inner>") tag_list.append("</Outer>") #these are for the key tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("</Inner>") tag_list.append("</Outer>") tree_list_1B = [] xml_populate_trees(tag_list, tree_list_1B) result = xml_compare_helper(tree_list_1B[0], tree_list_1B[1]) self.assert_(result == True)
def test_compare_helper_1 (self) : """ compares 2 different trees and returns False """ tag_list = [] #These are for the main tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("</Inner>") tag_list.append("</Outer>") #these are for the key tree tag_list.append("<Outer>") tag_list.append("<Fatboy>") tag_list.append("</Fatboy>") tag_list.append("</Outer>") tree_list_1A = [] xml_populate_trees(tag_list, tree_list_1A) result = xml_compare_helper(tree_list_1A[0], tree_list_1A[1]) self.assert_(result == False)
def test_populate_trees_2 (self) : """ Creates a key and a main tree and checks for validity via their string methods """ tag_list = [] #These are for the main tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("<A>")#Grandchild of outer tag_list.append("</A>") tag_list.append("<B></B>")#Grandchild of outer MIGHT ERROR! tag_list.append("</Inner>") tag_list.append("</Outer>") #these are for the key tree tag_list.append("<Outer>") tag_list.append("<In>") tag_list.append("</In>") tag_list.append("<Soup>") tag_list.append("</Soup>") tag_list.append("</Outer>") tree_list_2 = [] xml_populate_trees(tag_list, tree_list_2) self.assert_( ET.tostring(tree_list_2[1]) == "<Outer><In /><Soup /></Outer>") self.assert_( ET.tostring(tree_list_2[0]) == "<Outer><Inner><A /><B /></Inner></Outer>") self.assert_(tree_list_2[0].tag == tree_list_2[1].tag)
def test_populate_trees_3 (self) : """ Tests multiple tree creations """ tag_list = [] #mainTree 1 tag_list.append("<Mone>") tag_list.append("</Mone>") #keyTree 1 tag_list.append("<Kone>") tag_list.append("</Kone>") #mainTree 2 tag_list.append("<Mtwo>") tag_list.append("</Mtwo>") #keyTree 2 tag_list.append("<Ktwo>") tag_list.append("</Ktwo>") #mainTree 3 tag_list.append("<Mthree>") tag_list.append("</Mthree>") #keyTree 3 tag_list.append("<Kthree>") tag_list.append("</Kthree>") #mainTree 4 tag_list.append("<Mfour>") tag_list.append("</Mfour>") #keyTree 4 tag_list.append("<Kfour>") tag_list.append("</Kfour>") tree_list_3 = [] xml_populate_trees(tag_list, tree_list_3) self.assert_(len(tree_list_3) == 8) self.assert_(ET.tostring(tree_list_3[0]) == "<Mone />"); self.assert_(ET.tostring(tree_list_3[1]) == "<Kone />"); self.assert_(ET.tostring(tree_list_3[2]) == "<Mtwo />"); self.assert_(ET.tostring(tree_list_3[3]) == "<Ktwo />"); self.assert_(ET.tostring(tree_list_3[4]) == "<Mthree />"); self.assert_(ET.tostring(tree_list_3[5]) == "<Kthree />"); self.assert_(ET.tostring(tree_list_3[6]) == "<Mfour />"); self.assert_(ET.tostring(tree_list_3[7]) == "<Kfour />");
def test_compare_2 (self) : """ finds one match at the 2nd element """ tag_list = [] #mainTree tag_list.append("<Z>") tag_list.append("<A>") tag_list.append("<C>") tag_list.append("<D>") tag_list.append("</D>") tag_list.append("<E>") tag_list.append("</E>") tag_list.append("</C>") tag_list.append("</A>") tag_list.append("</Z>") #keyTree tag_list.append("<A>") tag_list.append("<C>") tag_list.append("<D>") tag_list.append("</D>") tag_list.append("</C>") tag_list.append("</A>") tree_list = [] xml_populate_trees(tag_list, tree_list) matches = [] xml_compare(tree_list[0], tree_list[1], matches) self.assert_(len(matches) == 1) self.assert_(matches[0] == 2)
def test_compare_3 (self) : """ Finds a key with two siblings """ tag_list = [] #mainTree tag_list.append("<A>") tag_list.append("<Very>") tag_list.append("<Bad>") tag_list.append("</Bad>") tag_list.append("<Story>") tag_list.append("</Story>") tag_list.append("</Very>") tag_list.append("</A>") #keyTree tag_list.append("<Very>") tag_list.append("<Bad>") tag_list.append("</Bad>") tag_list.append("<Story>") tag_list.append("</Story>") tag_list.append("</Very>") tree_list = [] xml_populate_trees(tag_list, tree_list) matches = [] xml_compare(tree_list[0], tree_list[1], matches) self.assert_(len(matches) == 1) self.assert_(matches[0] == 2)
def test_populate_trees_1 (self) : """ Creates 2 identical trees for the main and key and compares """ tag_list = [] #These are for the main tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("</Inner>") tag_list.append("</Outer>") #these are for the key tree tag_list.append("<Outer>") tag_list.append("<Inner>") tag_list.append("</Inner>") tag_list.append("</Outer>") tree_list_1 = [] xml_populate_trees(tag_list, tree_list_1) self.assert_(tree_list_1[0].tag == tree_list_1[1].tag) self.assert_(ET.tostring(tree_list_1[0]) == ET.tostring(tree_list_1[1]))