Beispiel #1
0
 def test_xml_search_3 (self) :
     XML.index = 1
     l = []
     xml = fromstring("<xml><a></a><dog></dog></xml>")
     p = fromstring("<dog></dog>")
     d = ["dog"]
     xml_search(xml, p, d, l)
     self.assertTrue(l[0] == 3)
     self.assertTrue(len(l) == 1)
Beispiel #2
0
 def test_xml_search_1 (self) :
     XML.index = 1
     l = []
     xml = fromstring("<xml><a></a></xml>")
     p = fromstring("<a></a>")
     d = ["a"]
     xml_search(xml, p, d, l)
     self.assertTrue(l[0] == 2)
     self.assertTrue(len(l) == 1)
    def test_search_2 (self) :

        s = "<Sports>\n"\
            "<Basketball>\n"\
            "<athletes>\n"\
            "<Kobe></Kobe>\n"\
            "<Lebron></Lebron>\n"\
            "<Durant></Durant>\n"\
            "<Carmelo></Carmelo>\n"\
            "</athletes>\n"\
            "</Basketball>\n"\
            "<Soccer>\n"\
            "<athletes>\n"\
            "<Messi></Messi>\n"\
            "<CRonaldo></CRonaldo>\n"\
            "<Iniesta></Iniesta>\n"\
            "<Xavi></Xavi>\n"\
            "<Kobe></Kobe>\n"\
            "</athletes>\n"\
            "</Soccer>\n"\
            "<Legends>\n"\
            "<Ronaldo></Ronaldo>\n"\
            "<Zidane></Zidane>\n"\
            "<Kobe></Kobe>\n"\
            "<Figo></Figo>\n"\
            "</Legends>\n"\
            "<CareerPoints>\n"\
            "<Kobe></Kobe>\n"\
            "</CareerPoints>\n"\
            "</Sports>\n"

        l = "<athletes><Kobe></Kobe></athletes>"
        v = xml_search(s, l)
        self.assert_(v == [2, 3, 9])
 def test_search_1(self):
     refined_list = ['THU', 'Team', 'ACRush', '/ACRush', 'Cooly', '/Cooly', 'Jelly', '/Jelly', '/Team', 'JiaJia', 'Team', 'Dragon', '/Dragon', 'Cooly', '/Cooly', '/Team', '/JiaJia', '/THU']
     query_list = ['Team', 'Cooly', '/Cooly', '/Team']
     pclist = [1, 2, 3, 2, 3, 2, 3, 2, 1, 2, 3, 4, 3, 4, 3, 2, 1, 0]
     test = xml_search(refined_list, query_list, pclist)
     self.assert_(test[0] == 2)
     self.assert_(test[1] == 7)
    def test_search_4 (self) :

        s = "<ANIMALS>\n"\
            "<Dogs>\n"\
            "<Rabbits></Rabbits>\n"\
            "<Frogs></Frogs>\n"\
            "</Dogs>\n"\
            "<Cheetahs></Cheetahs>\n"\
            "</ANIMALS>\n"

        l = "<Dogs><Cheetahs></Cheetahs></Dogs>"
        v = xml_search(s, l)
        self.assert_(v == [0])
	def test_search_2 (self) :
		r = StringIO.StringIO("""<Tag1>
					 	<Tag2>
							<Tag3></Tag3>
							<Tag4></Tag4>
						</Tag2>
						<Tag5></Tag5>
					</Tag1>
					<Tag2>
						<Tag4></Tag4>
					</Tag2>""")
		tmp = xml_read(r)
		matches = xml_search(list(tmp)[0], list(tmp)[1])
		assert matches == [2]
 def test_search_1 (self) :
     s = "<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"
     l = "<Team><Cooly></Cooly></Team>"
     v = xml_search(s, l)
     self.assert_(v == [2, 2, 7])
	def test_search_8 (self) :
		r = StringIO.StringIO("""
			<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> """)
		tmp = xml_read(r)
		matches = xml_search(list(tmp)[0], list(tmp)[1])
		assert matches == [2, 7]
    def test_search_3 (self) :

        s = "<year>\n"\
           "<month>\n"\
           "<octb></octb>\n"\
           "<jan></jan>\n"\
           "<mar></mar>\n"\
           "</month>\n"\
           "<holiday>\n"\
           "<octb></octb>\n"\
           "<feb></feb>\n"\
           "</holiday>\n"\
           "<halloween>\n"\
           "<octb></octb>\n"\
           "<jan></jan>\n"\
           "</halloween>\n"\
           "</year>"

        l = "<month><octb></octb></month>"
        v = xml_search(s, l)
        self.assert_(v == [1, 2])
Beispiel #10
0
 def test_xml_search_2 (self) :
     i = io.StringIO("<zap><blam><A><B><C><Z></Z></C><A></A></B></A><B><D></D></B><A><B><C><Z><F></F></Z></C></B><D></D></A></blam></zap><A><B><C><Z></Z></C></B></A>")
     o = io.StringIO()
     xml_search(i, o)
     self.assertTrue(o.getvalue() == "2\n3\n10")
Beispiel #11
0
 def test_xml_search (self) :
     i = io.StringIO("<A><B><C></C><A></A><D></D></B></A><A><D></D></A>")
     o = io.StringIO()
     xml_search(i, o)
     self.assertTrue(o.getvalue() == "1\n4")
 def test_xml_search1(self):
   r = StringIO.StringIO("<THU><Team></Team></THU>\n<Team></Team>")
   w = StringIO.StringIO()
   xml_search(r, w)
   self.assert_(w.getvalue() == "1\n2\n")
Beispiel #13
0
"""
To run the program
    % python RunXML.py < RunXML.in > RunXML.out
    % chmod ugo+x RunXML.py
    % RunXML.py < RunXML.in > RunXML.out

To document the program
    % pydoc -w XML
"""

# -------
# imports
# -------

import sys

import XML
from XML import xml_assign_id, xml_potentials, xml_check, xml_matches, xml_print, xml_search

# ----
# main
# ----

xml_search(sys.stdin, sys.stdout)