1.1 --- a/tests/begat.py Sat May 14 23:32:41 2005 +0000
1.2 +++ b/tests/begat.py Sun May 15 13:48:37 2005 +0000
1.3 @@ -7,28 +7,70 @@
1.4 """
1.5
1.6 import libxml2macro as n_
1.7 -import time, os
1.8 +
1.9 +def test_begat_libxml2macro(n_doc, full_xpath):
1.10 + l = []
1.11
1.12 -raw_input("Start your engines with ps -p %s -fv" % os.getpid())
1.13 -t = time.time()
1.14 + if full_xpath:
1.15 + for n_node in n_doc.xpath("//v[contains(text(), 'begat')]"):
1.16 + text = n_node.nodeValue
1.17 + l.append(text)
1.18 + else:
1.19 + # NOTE: Code corresponding to this was suggested for cElementTree, but why not
1.20 + # NOTE: take full advantage of XPath if you have most of the code written in C?
1.21
1.22 -l = []
1.23 -n_doc = parseFile("ot.xml")
1.24 -for n_node in n_doc.xpath("//v[contains(text(), 'begat')]"):
1.25 - text = n_node.nodeValue
1.26 - l.append(text)
1.27 + for n_node in n_doc.xpath("//v"):
1.28 + text = n_node.nodeValue
1.29 + if text.find(u'begat') != -1:
1.30 + l.append(text)
1.31 +
1.32 + return l
1.33 +
1.34 +def test_begat_libxml2dom(doc, full_xpath):
1.35 + l = []
1.36 +
1.37 + if full_xpath:
1.38 + for node in doc.xpath("//v[contains(text(), 'begat')]"):
1.39 + text = node.nodeValue
1.40 + l.append(text)
1.41 + else:
1.42 + # NOTE: Code corresponding to this was suggested for cElementTree, but why not
1.43 + # NOTE: take full advantage of XPath if you have most of the code written in C?
1.44
1.45 -# NOTE: Code corresponding to this was suggested for cElementTree, but why not
1.46 -# NOTE: take full advantage of XPath if you have most of the code written in C?
1.47 -#
1.48 -# for n_node in n_doc.xpath("//v"):
1.49 -# text = n_node.nodeValue
1.50 -# if text.find(u'begat') != -1:
1.51 -# print text
1.52 + for node in doc.xpath("//v"):
1.53 + text = node.nodeValue
1.54 + if text.find(u'begat') != -1:
1.55 + l.append(text)
1.56 +
1.57 + return l
1.58 +
1.59 +if __name__ == "__main__":
1.60 + import time, os
1.61 + import sys
1.62 +
1.63 + ot_locations = [arg for arg in sys.argv if arg.endswith("ot.xml")]
1.64 + full_xpath = "--full" in sys.argv
1.65 + use_libxml2dom = "libxml2dom" in sys.argv
1.66 + use_libxml2macro = "libxml2macro" in sys.argv
1.67
1.68 -print "Time taken", time.time() - t
1.69 -raw_input("Stop your engines!")
1.70 + if len(ot_locations) == 0:
1.71 + print "Please specify the location of the ot.xml file."
1.72 + sys.exit(1)
1.73 +
1.74 + raw_input("Start your engines with ps -p %s -fv" % os.getpid())
1.75 + t = time.time()
1.76
1.77 -print l
1.78 + if use_libxml2macro:
1.79 + n_doc = parseFile(ot_locations[0])
1.80 + l = test_begat_libxml2macro(n_doc, full_xpath)
1.81 + else: # use_libxml2dom:
1.82 + import libxml2dom
1.83 + doc = libxml2dom.parse(ot_locations[0])
1.84 + l = test_begat_libxml2dom(doc, full_xpath)
1.85 +
1.86 + print "Time taken", time.time() - t
1.87 + raw_input("Stop your engines!")
1.88 +
1.89 + print l
1.90
1.91 # vim: tabstop=4 expandtab shiftwidth=4