1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-28 00:21:53 +03:00

adding error redirections and preformat to a python handler cleanup made

* python/Makefile.am python/libxml.c python/libxml2-python-api.xml
  python/libxml2class.txt: adding error redirections and preformat
  to a python handler
* python/tests/Makefile.am python/tests/*.py: cleanup made all
  tests self checking
Daniel
This commit is contained in:
Daniel Veillard
2002-02-02 21:49:17 +00:00
parent 7fd7a94aa8
commit 5d81903b06
11 changed files with 184 additions and 28 deletions

View File

@ -4,6 +4,7 @@ TESTS= \
tst.py \
tstxpath.py \
xpathext.py \
error.py \
xpath.py
XMLS= \
@ -13,7 +14,7 @@ EXTRA_DIST = $(TESTS) $(XMLS)
if WITH_PYTHON
tests: $(TESTS)
-@(CLASSPATH=".." ; export CLASSPATH; \
-@(PYTHONPATH=".." ; export PYTHONPATH; \
for test in $(TESTS) ; do echo "-- $$test" ; $(PYTHON) $$test ; done)
else
tests:

View File

@ -1,10 +1,18 @@
#!/usr/bin/python -u
import sys
import libxml2
doc = libxml2.parseFile("tst.xml")
print doc.name
if doc.name != "tst.xml":
print "doc.name failed"
sys.exit(1)
root = doc.children
print root.name
if root.name != "doc":
print "root.name failed"
sys.exit(1)
child = root.children
print child.name
if child.name != "foo":
print "child.name failed"
sys.exit(1)
doc.freeDoc()
print "OK"

View File

@ -1,29 +1,38 @@
#!/usr/bin/python -u
import sys
import libxml2
def foo(x):
# print "foo called %s" % (x)
return x + 1
def bar(x):
# print "foo called %s" % (x)
return "%s" % (x + 1)
return "%d" % (x + 2)
doc = libxml2.parseFile("tst.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
print res
if len(res) != 2:
print "xpath query: wrong node set size"
sys.exit(1)
if res[0].name != "doc" or res[1].name != "foo":
print "xpath query: wrong node set value"
sys.exit(1)
libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
i = 10000
while i > 0:
res = ctxt.xpathEval("foo(1)")
if res != 2:
print "xpath extension failure"
sys.exit(1)
i = i - 1
print res
i = 10000
while i > 0:
res = ctxt.xpathEval("bar(1)")
if res != "3":
print "xpath extension failure got %s expecting '3'"
sys.exit(1)
i = i - 1
print res
doc.freeDoc()
print "OK"

View File

@ -3,10 +3,23 @@
# this test exercise the XPath basic engine, parser, etc, and
# allows to detect memory leaks
#
import sys
import libxml2
doc = libxml2.parseFile("tst.xml")
print doc
if doc.name != "tst.xml":
print "doc.name error"
sys.exit(1);
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
if len(res) != 2:
print "xpath query: wrong node set size"
sys.exit(1)
if res[0].name != "doc" or res[1].name != "foo":
print "xpath query: wrong node set value"
sys.exit(1)
doc.freeDoc()
i = 1000
while i > 0:
doc = libxml2.parseFile("tst.xml")
@ -14,8 +27,4 @@ while i > 0:
res = ctxt.xpathEval("//*")
doc.freeDoc()
i = i -1
doc = libxml2.parseFile("tst.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
print res
doc.freeDoc()
print "OK"

View File

@ -1,33 +1,38 @@
#!/usr/bin/python -u
#
# This test exercise the extension of the XPath engine with
# functions defined in Python.
#
import sys
import libxml2
def foo(x):
# print "foo called %s" % (x)
return x + 1
def bar(x):
# print "foo called %s" % (x)
return "%s" % (x + 1)
return "%d" % (x + 2)
doc = libxml2.parseFile("tst.xml")
ctxt = doc.xpathNewContext()
res = ctxt.xpathEval("//*")
print res
if len(res) != 2:
print "xpath query: wrong node set size"
sys.exit(1)
if res[0].name != "doc" or res[1].name != "foo":
print "xpath query: wrong node set value"
sys.exit(1)
libxml2.registerXPathFunction(ctxt._o, "foo", None, foo)
libxml2.registerXPathFunction(ctxt._o, "bar", None, bar)
i = 10000
while i > 0:
res = ctxt.xpathEval("foo(1)")
if res != 2:
print "xpath extension failure"
sys.exit(1)
i = i - 1
print res
i = 10000
while i > 0:
res = ctxt.xpathEval("bar(1)")
if res != "3":
print "xpath extension failure got %s expecting '3'"
sys.exit(1)
i = i - 1
print res
doc.freeDoc()
print "OK"