Annotation of embedaddon/libxml2/python/tests/ctxterror.py, revision 1.1
1.1 ! misho 1: #!/usr/bin/python -u
! 2: #
! 3: # This test exercise the redirection of error messages with a
! 4: # functions defined in Python.
! 5: #
! 6: import sys
! 7: import libxml2
! 8:
! 9: # Memory debug specific
! 10: libxml2.debugMemory(1)
! 11:
! 12: expect="""--> (3) xmlns: URI foo is not absolute
! 13: --> (4) Opening and ending tag mismatch: x line 0 and y
! 14: """
! 15:
! 16: err=""
! 17: def callback(arg,msg,severity,reserved):
! 18: global err
! 19: err = err + "%s (%d) %s" % (arg,severity,msg)
! 20:
! 21: s = """<x xmlns="foo"></y>"""
! 22:
! 23: parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
! 24: parserCtxt.setErrorHandler(callback, "-->")
! 25: if parserCtxt.getErrorHandler() != (callback,"-->"):
! 26: print "getErrorHandler failed"
! 27: sys.exit(1)
! 28: parserCtxt.parseChunk(s,len(s),1)
! 29: doc = parserCtxt.doc()
! 30: doc.freeDoc()
! 31: parserCtxt = None
! 32:
! 33: if err != expect:
! 34: print "error"
! 35: print "received %s" %(err)
! 36: print "expected %s" %(expect)
! 37: sys.exit(1)
! 38:
! 39: i = 10000
! 40: while i > 0:
! 41: parserCtxt = libxml2.createPushParser(None,"",0,"test.xml")
! 42: parserCtxt.setErrorHandler(callback, "-->")
! 43: parserCtxt.parseChunk(s,len(s),1)
! 44: doc = parserCtxt.doc()
! 45: doc.freeDoc()
! 46: parserCtxt = None
! 47: err = ""
! 48: i = i - 1
! 49:
! 50: # Memory debug specific
! 51: libxml2.cleanupParser()
! 52: if libxml2.debugMemory(1) == 0:
! 53: print "OK"
! 54: else:
! 55: print "Memory leak %d bytes" % (libxml2.debugMemory(1))
! 56: libxml2.dumpMemory()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>