~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to Externals/LibXML/python/tests/ctxterror.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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()