VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/reader4.py@ 107065

Last change on this file since 107065 was 105420, checked in by vboxsync, 8 months ago

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/env python3
2#
3# this tests the basic APIs of the XmlTextReader interface
4#
5import setup_test
6import libxml2
7import sys
8try:
9 import StringIO
10 str_io = StringIO.StringIO
11except:
12 import io
13 str_io = io.StringIO
14
15# Memory debug specific
16libxml2.debugMemory(1)
17
18def tst_reader(s):
19 f = str_io(s)
20 input = libxml2.inputBuffer(f)
21 reader = input.newTextReader("tst")
22 res = ""
23 while reader.Read():
24 res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
25 reader.Value(), reader.IsEmptyElement())
26 if reader.NodeType() == 1: # Element
27 while reader.MoveToNextAttribute():
28 res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
29 reader.Name(),reader.Value())
30 return res
31
32expect="""1 (test) [None] 0
331 (b) [None] 1
341 (c) [None] 1
3515 (test) [None] 0
36"""
37
38res = tst_reader("""<test><b/><c/></test>""")
39
40if res != expect:
41 print("Did not get the expected error message:")
42 print(res)
43 sys.exit(1)
44
45# Memory debug specific
46libxml2.cleanupParser()
47if libxml2.debugMemory(1) == 0:
48 print("OK")
49else:
50 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette