Blame python/tests/ctxterror.py

Packit 423ecb
#!/usr/bin/python -u
Packit 423ecb
#
Packit 423ecb
# This test exercise the redirection of error messages with a
Packit 423ecb
# functions defined in Python.
Packit 423ecb
#
Packit 423ecb
import sys
Packit 423ecb
import libxml2
Packit 423ecb
Packit 423ecb
# Memory debug specific
Packit 423ecb
libxml2.debugMemory(1)
Packit 423ecb
Packit 423ecb
expect="""--> (3) xmlns: URI foo is not absolute
Packit 423ecb
--> (4) Opening and ending tag mismatch: x line 0 and y
Packit 423ecb
"""
Packit 423ecb
Packit 423ecb
err=""
Packit 423ecb
def callback(arg,msg,severity,reserved):
Packit 423ecb
    global err
Packit 423ecb
    err = err + "%s (%d) %s" % (arg,severity,msg)
Packit 423ecb
Packit 423ecb
s = """<x xmlns="foo"></y>"""
Packit 423ecb
Packit 423ecb
parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
Packit 423ecb
parserCtxt.setErrorHandler(callback, "-->")
Packit 423ecb
if parserCtxt.getErrorHandler() != (callback,"-->"):
Packit 423ecb
    print("getErrorHandler failed")
Packit 423ecb
    sys.exit(1)
Packit 423ecb
parserCtxt.parseChunk(s,len(s),1)
Packit 423ecb
doc = parserCtxt.doc()
Packit 423ecb
doc.freeDoc()
Packit 423ecb
parserCtxt = None
Packit 423ecb
Packit 423ecb
if err != expect:
Packit 423ecb
    print("error")
Packit 423ecb
    print("received %s" %(err))
Packit 423ecb
    print("expected %s" %(expect))
Packit 423ecb
    sys.exit(1)
Packit 423ecb
Packit 423ecb
i = 10000
Packit 423ecb
while i > 0:
Packit 423ecb
    parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
Packit 423ecb
    parserCtxt.setErrorHandler(callback, "-->")
Packit 423ecb
    parserCtxt.parseChunk(s,len(s),1)
Packit 423ecb
    doc = parserCtxt.doc()
Packit 423ecb
    doc.freeDoc()
Packit 423ecb
    parserCtxt = None
Packit 423ecb
    err = ""
Packit 423ecb
    i = i - 1
Packit 423ecb
Packit 423ecb
# Memory debug specific
Packit 423ecb
libxml2.cleanupParser()
Packit 423ecb
if libxml2.debugMemory(1) == 0:
Packit 423ecb
    print("OK")
Packit 423ecb
else:
Packit 423ecb
    print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
Packit 423ecb
    libxml2.dumpMemory()