~ubuntu-branches/ubuntu/wily/libxml2/wily-proposed

« back to all changes in this revision

Viewing changes to python/tests/outbuf.py

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-07-11 09:31:50 UTC
  • mfrom: (43.2.4 sid)
  • Revision ID: package-import@ubuntu.com-20130711093150-t3vcnrpfqepqt0mp
Tags: 2.9.1+dfsg1-2ubuntu1
* Merged from Debian unstable. Remaining changes:
  - Fix python multi-arch includes issues. 
  - Allow the package to cross-build.
  - Set PYTHON_LIBS for cross builds.
  - Remove explicit build dependency on binutils.
  - Configure the udeb --without-python.
* Dropped patches:
  - CVE-2013-0338.patch: upstream
  - CVE-2013-1969.patch: upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python -u
2
2
import sys
3
3
import libxml2
4
 
import StringIO
 
4
try:
 
5
    import StringIO
 
6
    str_io = StringIO.StringIO
 
7
except:
 
8
    import io
 
9
    str_io = io.StringIO
5
10
 
6
11
def testSimpleBufferWrites():
7
 
    f = StringIO.StringIO()
 
12
    f = str_io()
8
13
    buf = libxml2.createOutputBuffer(f, "ISO-8859-1")
9
14
    buf.write(3, "foo")
10
15
    buf.writeString("bar")
11
16
    buf.close()
12
 
    
 
17
 
13
18
    if f.getvalue() != "foobar":
14
 
        print "Failed to save to StringIO"
 
19
        print("Failed to save to StringIO")
15
20
        sys.exit(1)
16
21
 
17
22
def testSaveDocToBuffer():
23
28
<?xml version="1.0" encoding="UTF-8"?>
24
29
<foo>Hello</foo>
25
30
'''
26
 
    f = StringIO.StringIO()
 
31
    f = str_io()
27
32
    buf = libxml2.createOutputBuffer(f, 'UTF-8')
28
33
    doc = libxml2.parseDoc(input)
29
34
    doc.saveFileTo(buf, 'UTF-8')
30
35
    doc.freeDoc()
31
36
    if f.getvalue() != expected:
32
 
        print 'xmlDoc.saveFileTo() call failed.'
33
 
        print '     got: %s' % repr(f.getvalue())
34
 
        print 'expected: %s' % repr(expected)
 
37
        print('xmlDoc.saveFileTo() call failed.')
 
38
        print('     got: %s' % repr(f.getvalue()))
 
39
        print('expected: %s' % repr(expected))
35
40
        sys.exit(1)
36
41
 
37
42
def testSaveFormattedDocToBuffer():
49
54
''')
50
55
    doc = libxml2.parseDoc(input)
51
56
    for i in (0, 1):
52
 
        f = StringIO.StringIO()
 
57
        f = str_io()
53
58
        buf = libxml2.createOutputBuffer(f, 'UTF-8')
54
59
        doc.saveFormatFileTo(buf, 'UTF-8', i)
55
60
        if f.getvalue() != expected[i]:
56
 
            print 'xmlDoc.saveFormatFileTo() call failed.'
57
 
            print '     got: %s' % repr(f.getvalue())
58
 
            print 'expected: %s' % repr(expected[i])
 
61
            print('xmlDoc.saveFormatFileTo() call failed.')
 
62
            print('     got: %s' % repr(f.getvalue()))
 
63
            print('expected: %s' % repr(expected[i]))
59
64
            sys.exit(1)
60
65
    doc.freeDoc()
61
66
 
69
74
<?xml version="1.0" encoding="UTF-8"?>
70
75
<foo>Hello</foo>
71
76
'''
72
 
    f = StringIO.StringIO()
 
77
    f = str_io()
73
78
    doc = libxml2.parseDoc(input)
74
79
    buf = libxml2.createOutputBuffer(f, 'UTF-8')
75
80
    buf.saveFileTo(doc, 'UTF-8')
76
81
    if f.getvalue() != expected:
77
 
        print 'outputBuffer.saveFileTo() call failed.'
78
 
        print '     got: %s' % repr(f.getvalue())
79
 
        print 'expected: %s' % repr(expected)
 
82
        print('outputBuffer.saveFileTo() call failed.')
 
83
        print('     got: %s' % repr(f.getvalue()))
 
84
        print('expected: %s' % repr(expected))
80
85
        sys.exit(1)
81
 
    f = StringIO.StringIO()
 
86
    f = str_io()
82
87
    buf = libxml2.createOutputBuffer(f, 'UTF-8')
83
88
    buf.saveFormatFileTo(doc, 'UTF-8', 1)
84
89
    if f.getvalue() != expected:
85
 
        print 'outputBuffer.saveFormatFileTo() call failed.'
86
 
        print '     got: %s' % repr(f.getvalue())
87
 
        print 'expected: %s' % repr(expected)
 
90
        print('outputBuffer.saveFormatFileTo() call failed.')
 
91
        print('     got: %s' % repr(f.getvalue()))
 
92
        print('expected: %s' % repr(expected))
88
93
        sys.exit(1)
89
94
    doc.freeDoc()
90
95
 
99
104
 
100
105
    libxml2.cleanupParser()
101
106
    if libxml2.debugMemory(1) == 0:
102
 
        print "OK"
 
107
        print("OK")
103
108
    else:
104
 
        print "Memory leak %d bytes" % (libxml2.debugMemory(1))
 
109
        print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
105
110
        libxml2.dumpMemory()