Annotation of embedaddon/libxml2/python/tests/reader4.py, revision 1.1.1.2

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 sys
1.1.1.2 ! misho       7: try:
        !             8:     import StringIO
        !             9:     str_io = StringIO.StringIO
        !            10: except:
        !            11:     import io
        !            12:     str_io = io.StringIO
1.1       misho      13: 
                     14: # Memory debug specific
                     15: libxml2.debugMemory(1)
                     16: 
                     17: def tst_reader(s):
1.1.1.2 ! misho      18:     f = str_io(s)
1.1       misho      19:     input = libxml2.inputBuffer(f)
                     20:     reader = input.newTextReader("tst")
                     21:     res = ""
                     22:     while reader.Read():
                     23:         res=res + "%s (%s) [%s] %d\n" % (reader.NodeType(),reader.Name(),
                     24:                                      reader.Value(), reader.IsEmptyElement())
                     25:         if reader.NodeType() == 1: # Element
                     26:             while reader.MoveToNextAttribute():
                     27:                 res = res + "-- %s (%s) [%s]\n" % (reader.NodeType(),
                     28:                                                   reader.Name(),reader.Value())
                     29:     return res
                     30:     
                     31: expect="""1 (test) [None] 0
                     32: 1 (b) [None] 1
                     33: 1 (c) [None] 1
                     34: 15 (test) [None] 0
                     35: """
                     36: 
                     37: res = tst_reader("""<test><b/><c/></test>""")
                     38: 
                     39: if res != expect:
1.1.1.2 ! misho      40:     print("Did not get the expected error message:")
        !            41:     print(res)
1.1       misho      42:     sys.exit(1)
                     43: 
                     44: # Memory debug specific
                     45: libxml2.cleanupParser()
                     46: if libxml2.debugMemory(1) == 0:
1.1.1.2 ! misho      47:     print("OK")
1.1       misho      48: else:
1.1.1.2 ! misho      49:     print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
1.1       misho      50:     libxml2.dumpMemory()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>