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

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