error.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # Memory debug specific
  9. libxml2.debugMemory(1)
  10. expect='--> I/O --> warning : --> failed to load external entity "missing.xml"\n'
  11. err=""
  12. def callback(ctx, str):
  13. global err
  14. err = err + "%s %s" % (ctx, str)
  15. got_exc = 0
  16. libxml2.registerErrorHandler(callback, "-->")
  17. try:
  18. doc = libxml2.parseFile("missing.xml")
  19. except libxml2.parserError:
  20. got_exc = 1
  21. if got_exc == 0:
  22. print "Failed to get a parser exception"
  23. sys.exit(1)
  24. if err != expect:
  25. print "error"
  26. print "received %s" %(err)
  27. print "expected %s" %(expect)
  28. sys.exit(1)
  29. i = 10000
  30. while i > 0:
  31. try:
  32. doc = libxml2.parseFile("missing.xml")
  33. except libxml2.parserError:
  34. got_exc = 1
  35. err = ""
  36. i = i - 1
  37. # Memory debug specific
  38. libxml2.cleanupParser()
  39. if libxml2.debugMemory(1) == 0:
  40. print "OK"
  41. else:
  42. print "Memory leak %d bytes" % (libxml2.debugMemory(1))
  43. libxml2.dumpMemory()