Annotation of embedaddon/libxml2/python/tests/readererr.py, revision 1.1.1.1
1.1 misho 1: #!/usr/bin/python -u
2: #
3: # this tests the basic APIs of the XmlTextReader interface
4: #
5: import libxml2
6: import StringIO
7: import sys
8:
9: # Memory debug specific
10: libxml2.debugMemory(1)
11:
12: expect="""--> (3) test1:1:xmlns: URI foo is not absolute
13: --> (4) test1:1:Opening and ending tag mismatch: c line 1 and a
14: """
15: err=""
16: def myErrorHandler(arg,msg,severity,locator):
17: global err
18: err = err + "%s (%d) %s:%d:%s" % (arg,severity,locator.BaseURI(),locator.LineNumber(),msg)
19:
20: f = StringIO.StringIO("""<a xmlns="foo"><b b1="b1"/><c>content of c</a>""")
21: input = libxml2.inputBuffer(f)
22: reader = input.newTextReader("test1")
23: reader.SetErrorHandler(myErrorHandler,"-->")
24: while reader.Read() == 1:
25: pass
26:
27: if err != expect:
28: print "error"
29: print "received %s" %(err)
30: print "expected %s" %(expect)
31: sys.exit(1)
32:
33: reader.SetErrorHandler(None,None)
34: if reader.GetErrorHandler() != (None,None):
35: print "GetErrorHandler failed"
36: sys.exit(1)
37:
38: #
39: # cleanup for memory allocation counting
40: #
41: del f
42: del input
43: del reader
44:
45: # Memory debug specific
46: libxml2.cleanupParser()
47: if libxml2.debugMemory(1) == 0:
48: print "OK"
49: else:
50: print "Memory leak %d bytes" % (libxml2.debugMemory(1))
51: libxml2.dumpMemory()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>