def test_eval2(self): a = [] r = StringIO.StringIO( "<RADIOHEAD>\n\t<DOWN>\n\t\t<UP>\n\t\t\t<NO>\n\t\t\t\t<KARMA></KARMA>\n\t\t\t\t<LET></LET>\n\t\t\t</NO>\n\t\t</UP>\n\t</DOWN>\n\t<FITTER>\n\t\t<POLICE></POLICE>\n\t</FITTER>\n\t<UP>\n\t\t<AIRBAG>\n\t\t\t<HAPPIER></HAPPIER>\n\t\t</AIRBAG>\n\t</UP>\n</RADIOHEAD>\n<UP>\n\t<DOWN>\n\t</DOWN>\n</UP>\n" ) key, block, path = xml_read(r) xml_eval(a, key, block, path) self.assert_(a == [0])
def test_eval3(self): a = [] r = StringIO.StringIO( "<RADIOHEAD>\n\t<THE>\n\t\t<MUSIC>\n\t\t\t<OK></OK>\n\t\t</MUSIC>\n\t</THE>\n\t<TOURIST>\n\t\t<THE></THE>\n\t</TOURIST>\n\t<FITTER>\n\t\t<EXIT>\n\t\t\t<WALLS></WALLS>\n\t\t\t<TOURIST></TOURIST>\n\t\t</EXIT>\n\t\t<HOMESICK>\n\t\t\t<DOWN>\n\t\t\t\t<MUSIC></MUSIC>\n\t\t\t</DOWN>\n\t\t</HOMESICK>\n\t</FITTER>\n\t<UP>\n\t\t<CLIMBING></CLIMBING>\n\t</UP>\n</RADIOHEAD>\n<RADIOHEAD>\n\t<THE>\n\t\t<MUSIC>\n\t\t\t<OK></OK>\n\t\t</MUSIC>\n\t</THE>\n\t<TOURIST>\n\t\t<THE></THE>\n\t</TOURIST>\n\t<FITTER>\n\t\t<EXIT>\n\t\t\t<WALLS></WALLS>\n\t\t\t<TOURIST></TOURIST>\n\t\t</EXIT>\n\t\t<HOMESICK>\n\t\t\t<DOWN>\n\t\t\t\t<MUSIC></MUSIC>\n\t\t\t</DOWN>\n\t\t</HOMESICK>\n\t</FITTER>\n\t<UP>\n\t\t<CLIMBING></CLIMBING>\n\t</UP>\n</RADIOHEAD>\n" ) key, block, path = xml_read(r) xml_eval(a, key, block, path) self.assert_(a == [1, 1])
def test_eval_no_result(self): solve_list = [0] test_list = [] r = StringIO.StringIO(pretty_print_string) tree = xml_read(r) xml_separate(tree, test_list) xml_eval(test_list, solve_list) self.assert_(solve_list[0] == 0)
def test_eval1(self): a = [] r = StringIO.StringIO( "<THU>\n\t<Team>\n\t\t<ACRush></ACRush>\n\t\t<Jelly></Jelly>\n\t\t<Cooly></Cooly>\n\t</Team>\n\t<JiaJia>\n\t\t<Team>\n\t\t\t<Ahyangyi></Ahyangyi>\n\t\t\t<Dragon></Dragon>\n\t\t\t<Cooly><Amber></Amber></Cooly>\n\t\t</Team>\n\t</JiaJia>\n</THU>\n<Team><Cooly></Cooly></Team>\n" ) key, block, path = xml_read(r) xml_eval(a, key, block, path) self.assert_(a == [2, 2, 7])
def test_eval_default_2(self): solve_list = [0] test_list = [] r = StringIO.StringIO(default_string2) tree = xml_read(r) xml_separate(tree, test_list) xml_eval(test_list, solve_list) self.assert_(solve_list[0] == 1) self.assert_(solve_list[1] == 5)
def test_eval_3 (self) : a = [fromstring("<apple><apple></apple><orange><apple></apple></orange></apple>"), fromstring("<apple></apple>")] i,j = a list = [] occur = [0] xml_eval(i, j, 0, occur, list, j.tag) self.assertTrue(occur[0] == 3) self.assertTrue(list== [1,2,4]) self.assertTrue(j.tag == "apple")
def test_eval_4 (self) : a = [fromstring("<peach><orange><apple></apple></orange></peach>"), fromstring("<peach><apple></apple></peach>")] i,j = a list = [] occur = [0] xml_eval(i, j, 0, occur, list, j.tag) self.assertTrue(occur[0] == 0) self.assertTrue(list == []) self.assertTrue(j.tag == "peach")
def test_eval_1 (self) : a = [fromstring("<parent1><child1><grandchild1></grandchild1></child1></parent1>"), fromstring("<child1><grandchild1></grandchild1></child1>")] i,j = a list = [] occur = [0] xml_eval(i, j, 0, occur, list, j.tag) self.assertTrue(occur[0] == 1) self.assertTrue(list[0] == 2) self.assertTrue(j.tag == "child1")
def test_eval_1(self): r = StringIO.StringIO("<THU>\n</THU>\n<THU></THU>\n") a = xml_read(r) assert type(a[0]) is ET.Element assert type(a[1]) is ET.Element result = xml_eval(a) assert(result[0][0] == 1)
def test_print_1(self) : r = StringIO.StringIO("<THU>\n</THU>\n<THU></THU>\n") w = StringIO.StringIO() a = xml_read(r) data = xml_eval(a) xml_print(w, data) self.assert_(w.getvalue() == "1\n1\n\n")
def test_eval_example_2(self): haystack = ET.fromstring( "<Team>\n\t\t\t<Ahyangyi></Ahyangyi>\n\t\t\t<Dragon></Dragon>\n\t\t\t<Cooly><Amber></Amber></Cooly>\n\t\t</Team>" ) needle = ET.fromstring("<Team><Cooly></Cooly></Team>") val = xml_eval(needle, haystack) self.assertEqual(val, 1)
def test_print_2(self) : r = StringIO.StringIO("<THU>\n<Team>\n<ACRush></ACRush>\n<Jelly></Jelly>\n<Cooly></Cooly>\n</Team>\n<JiaJia>\n<Team>\n<Ahyangyi></Ahyangyi>\n<Dragon></Dragon>\n<Cooly><Amber></Amber></Cooly>\n</Team>\n</JiaJia>\n</THU>\n<Team><Cooly></Cooly></Team>\n") w = StringIO.StringIO() a = xml_read(r) data = xml_eval(a) xml_print(w, data) self.assert_(w.getvalue() == "2\n2\n7\n\n")
def test_eval_4(self) : tree = ET.ElementTree(ET.fromstring(et_2_xml)).getroot() pattern_tree = ET.ElementTree(ET.fromstring(et_3_pattern)) pattern_root = pattern_tree.getroot() pattern = [pattern_root.tag] build_pattern_list(pattern_root, pattern) result = xml_eval(tree, pattern) self.assert_(result == [0,[]])
def test_eval_3 (self) : body = fromstring( "<Hogwarts><Gryffindor></Gryffindor><Ravenclaw></Ravenclaw></Hogwarts>") body = assign_location(body) query = fromstring( "<Hogwarts><Slytherin></Slytherin></Hogwarts>") top_element = "" count, location = xml_eval (body, query, [0], [], 0, top_element) self.assertTrue(count == [0]) self.assertTrue(location == [])
def test_eval_5 (self) : body = fromstring ("<red><green><blue></blue><yellow></yellow></green></red>") body = assign_location(body) query = fromstring ("<red><blue></blue></red>") top_element = "" count, location = xml_eval (body, query, [0], [], 0, top_element) self.assertTrue(count == [0]) self.assertTrue(location == ([]))
def test_eval_4 (self) : body = fromstring ("<Fruit><Berries><Strawberries></Strawberries></Berries><Berries><Strawberries></Strawberries></Berries></Fruit>") body = assign_location(body) query = fromstring ("<Berries><Strawberries></Strawberries></Berries>") top_element = "" count, location = xml_eval (body, query, [0], [], 0, top_element) self.assertTrue(count == [2]) self.assertTrue(location == ["2", "4"])
def test_eval_2 (self) : body = fromstring("<Drinks><Juice><Orange></Orange><Grape></Grape></Juice><Soda></Soda></Drinks>") body = assign_location(body) query = fromstring("<Drinks><Juice><Orange></Orange></Juice></Drinks>") top_element = "" count, location = xml_eval (body, query, [0], [], 0, top_element) self.assertTrue(count == [1]) self.assertTrue(location == ["1"])
def test_eval_2 (self) : XML.TAG_INDEX = 0 treeReader = io.StringIO("<THU><Team><ACRush></ACRush><Jelly></Jelly><Cooly></Cooly></Team><JiaJia><Team><Ahyangyi></Ahyangyi><Dragon></Dragon><Cooly><Amber></Amber></Cooly></Team></JiaJia></THU>") tree = ET.fromstring("<tree>" + treeReader.read() + "</tree>") patternReader = io.StringIO("<Team><Cooly></Cooly></Team>") pattern = ET.fromstring(patternReader.read()) matches = xml_eval(tree, pattern, []) self.assertTrue(matches == [2, 7])
def test_eval_1 (self) : XML.TAG_INDEX = 0 treeReader = io.StringIO("<one><two><three><four></four><five></five></three></two><ten><nine></nine><eight></eight><three><four></four><five></five></three></ten></one>") tree = ET.fromstring("<tree>" + treeReader.read() + "</tree>") patternReader = io.StringIO("<three><four></four><five></five></three>") pattern = ET.fromstring(patternReader.read()) matches = xml_eval(tree, pattern, []) self.assertTrue(matches == [3, 9])
def test_eval_3 (self) : XML.TAG_INDEX = 0 treeReader = io.StringIO("<a><b><c><d><e><f></f></e></d></c></b> <z><c><d><e></e><f></f></d><g></g></c></z></a>") tree = ET.fromstring("<tree>" + treeReader.read() + "</tree>") patternReader = io.StringIO("<c><d><e></e><f></f></d><g></g></c>") pattern = ET.fromstring(patternReader.read()) matches = xml_eval(tree, pattern, []) self.assertTrue(matches == [8])
def test_eval2 (self): line = 0 index = 0 pattern = ["Purple","Dragon"] lst = [] s = "<Fluffy>\n\t<Purple>\n\t\t<Dragon></Dragon>\n\t</Purple>\n</Fluffy>" tree = ET.fromstring(s) node = [tree] count = xml_eval(node,line,pattern,index,lst) self.assert_(count == 1) self.assert_(lst[0] == 2)
def test_eval3 (self): line = 0 index = 0 pattern = ["Pays","Bills"] lst = [] s = "<Swag>\n\t<Pays>\n\t\t<All></All>\n\t\t<The></The>\n\t\t<Bills></Bills>\n\t</Pays>\n\t<Hashtag>\n\t\t<Pays>\n\t\t\t<Bills></Bills>\n\t\t</Pays>\n\t</Hashtag>\n</Swag>" tree = ET.fromstring(s) node = [tree] count = xml_eval(node,line,pattern,index,lst) self.assert_(count == 2) self.assert_(lst[0] == 2) self.assert_(lst[1] == 7)
def test_eval (self): line = 0 index = 0 pattern = ["Team","Cooly"] lst = [] s = "<THU>\n\t<Team>\n\t\t<ACRush></ACRush>\n\t\t<Jelly></Jelly>\n\t\t<Cooly></Cooly>\n\t</Team>\n\t<JiaJia>\n\t\t<Team>\n\t\t\t<Ahyangyi></Ahyangyi>\n\t\t\t<Dragon></Dragon>\n\t\t\t<Cooly><Amber></Amber></Cooly>\n\t\t</Team>\n\t</JiaJia>\n</THU>" tree = ET.fromstring(s) node = [tree] count = xml_eval(node,line,pattern,index,lst) self.assert_(count == 2) self.assert_(lst[0] == 2) self.assert_(lst[1] == 7)
def test_eval_1(self): document = et.fromstring("""<gaurav_root><THU> <Team> <ACRush></ACRush> <Jelly></Jelly> <Cooly></Cooly> </Team> <JiaJia> <Team> <Ahyangyi></Ahyangyi> <Dragon></Dragon> <Cooly><Amber></Amber></Cooly> </Team> </JiaJia> </THU> <Team><Cooly></Cooly></Team></gaurav_root>""") ids = xml_eval(document[0], document[1]) self.assert_(ids == [ 2, 7 ])
def test_eval_3(self): v = xml_eval( """<THU> <Team> <ACRush></ACRush> <Jelly></Jelly> <Cooly></Cooly> </Team> <JiaJia> <Team> <Ahyangyi></Ahyangyi> <Dragon></Dragon> <Cooly><Amber></Amber></Cooly> </Team> </JiaJia> </THU>""", "<Team><Ahyangyi></Ahyangyi><Cooly><Amber></Amber></Cooly><Dragon></Dragon></Team>", ) self.assert_(v == [1, 7])
def test_eval_5(self) : r = StringIO.StringIO("<THU>\n<Cooley>\n<Hi>\n<WHAT></WHAT>\n</Hi>\n<Bye>\n</Bye>\n</Cooley>\n</THU>\n<Cooley><Hi><NOWAY></NOWAY></Hi><Bye></Bye></Cooley>\n") a = xml_read(r) result = xml_eval(a) assert(result[0][0] == 0)
def test_eval_4(self) : r = StringIO.StringIO("<THU>\n<Team>\n<ACRush></ACRush>\n<Jelly></Jelly>\n<Cooly></Cooly>\n</Team>\n<JiaJia>\n<Team>\n<Ahyangyi></Ahyangyi>\n<Dragon></Dragon>\n<Cooly><Amber></Amber></Cooly>\n</Team>\n</JiaJia>\n</THU>\n<Team><Cooly></Cooly></Team>\n") a = xml_read(r) result = xml_eval(a) self.assert_(result[0][0] == 2)
def test_eval_3(self): index = [1, 5, 7, 9] compare_pc = [0, 2] test = xml_eval(index, compare_pc) self.assert_(test == False)
def test_eval_1(self): index = [1, 5, 7, 9] compare_pc = [0, 1] test = xml_eval(index, compare_pc) self.assert_(test == True)
def test_eval_3(self): master = {1:'<Banana>',2:'<Hi>',3:'<Death></Death>',4:'<Team></Team>',5:'</HI>',6:'<Hi>',7:'<Death></Death',8:'</Hi>',9:'</Banana>',10:'<Hi><Death></Death></Hi>'} line_num = 10 iter, line_num_array = xml_eval(master, line_num) self.assert_(iter != 2) self.assert_(line_num_array != [2,6])