mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-17 18:21:05 +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:
72
python/tests/validate.py
Executable file
72
python/tests/validate.py
Executable 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"
|
Reference in New Issue
Block a user