1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

more accessor classes for the parser context, allow to switch on and check

* python/TODO python/generator.py python/libxml2-python-api.xml
  python/libxml2class.txt: more accessor classes for the parser
  context, allow to switch on and check validity
* python/tests/Makefile.am python/tests/error.py
  python/tests/invalid.xml python/tests/valid.xml
  python/tests/validate.py: attded more test and and added error.py
  which I forgot to commit in the last step
Daniel
This commit is contained in:
Daniel Veillard
2002-02-03 16:53:19 +00:00
parent 3ce5257b29
commit 26f1dcc5bd
10 changed files with 189 additions and 7 deletions

View File

@ -6,10 +6,13 @@ TESTS= \
xpathext.py \
push.py \
error.py \
validate.py \
xpath.py
XMLS= \
tst.xml
tst.xml \
valid.xml \
invalid.xml
EXTRA_DIST = $(TESTS) $(XMLS)

30
python/tests/error.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/python -u
#
# This test exercise the redirection of error messages with a
# functions defined in Python.
#
import sys
import libxml2
expect='--> warning: --> failed to load external entity "missing.xml"\n'
err=""
def callback(ctx, str):
global err
err = err + "%s %s" % (ctx, str)
libxml2.registerErrorHandler(callback, "-->")
doc = libxml2.parseFile("missing.xml")
if err != expect:
print "error"
print "received %s" %(err)
print "expected %s" %(expect)
sys.exit(1)
i = 10000
while i > 0:
doc = libxml2.parseFile("missing.xml")
err = ""
i = i - 1
print "OK"

6
python/tests/invalid.xml Normal file
View File

@ -0,0 +1,6 @@
<!DOCTYPE doc [
<!ELEMENT doc (a, b, a)>
<!ELEMENT a EMPTY>
<!ELEMENT b EMPTY>
]>
<doc><b/><a/><b/></doc>

4
python/tests/valid.xml Normal file
View File

@ -0,0 +1,4 @@
<!DOCTYPE doc [
<!ELEMENT doc EMPTY>
]>
<doc/>

72
python/tests/validate.py Executable file
View File

@ -0,0 +1,72 @@
#!/usr/bin/python -u
import sys
import libxml2
ctxt = libxml2.createFileParserCtxt("valid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()
if doc.name != "valid.xml":
print "doc.name failed"
sys.exit(1)
root = doc.children
if root.name != "doc":
print "root.name failed"
sys.exit(1)
if valid != 1:
print "validity chec failed"
sys.exit(1)
doc.freeDoc()
i = 1000
while i > 0:
ctxt = libxml2.createFileParserCtxt("valid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()
doc.freeDoc()
if valid != 1:
print "validity check failed"
sys.exit(1)
i = i - 1
#desactivate error messages from the validation
def noerr(ctx, str):
pass
libxml2.registerErrorHandler(noerr, None)
ctxt = libxml2.createFileParserCtxt("invalid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()
if doc.name != "invalid.xml":
print "doc.name failed"
sys.exit(1)
root = doc.children
if root.name != "doc":
print "root.name failed"
sys.exit(1)
if valid != 0:
print "validity chec failed"
sys.exit(1)
doc.freeDoc()
i = 1000
while i > 0:
ctxt = libxml2.createFileParserCtxt("invalid.xml")
ctxt.validate(1)
ctxt.parseDocument()
doc = ctxt.doc()
valid = ctxt.isValid()
doc.freeDoc()
if valid != 0:
print "validity check failed"
sys.exit(1)
i = i - 1
print "OK"