summaryrefslogtreecommitdiff
path: root/python/tests/reader2.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests/reader2.py')
-rwxr-xr-xpython/tests/reader2.py63
1 files changed, 27 insertions, 36 deletions
diff --git a/python/tests/reader2.py b/python/tests/reader2.py
index 8570575..ea890ec 100755
--- a/python/tests/reader2.py
+++ b/python/tests/reader2.py
@@ -5,13 +5,8 @@
import sys
import glob
import string
+import StringIO
import libxml2
-try:
- import StringIO
- str_io = StringIO.StringIO
-except:
- import io
- str_io = io.StringIO
# Memory debug specific
libxml2.debugMemory(1)
@@ -35,11 +30,7 @@ libxml2.registerErrorHandler(callback, "")
valid_files = glob.glob("../../test/valid/*.x*")
valid_files.sort()
for file in valid_files:
- if file.find("t8") != -1:
- continue
- if file == "../../test/valid/rss.xml":
- continue
- if file == "../../test/valid/xlink.xml":
+ if string.find(file, "t8") != -1:
continue
reader = libxml2.newTextReaderFilename(file)
#print "%s:" % (file)
@@ -48,11 +39,11 @@ for file in valid_files:
while ret == 1:
ret = reader.Read()
if ret != 0:
- print("Error parsing and validating %s" % (file))
+ print "Error parsing and validating %s" % (file)
#sys.exit(1)
if err != expect:
- print(err)
+ print err
#
# another separate test based on Stephane Bidoul one
@@ -88,7 +79,7 @@ expect="""10,test
res=""
err=""
-input = libxml2.inputBuffer(str_io(s))
+input = libxml2.inputBuffer(StringIO.StringIO(s))
reader = input.newTextReader("test2")
reader.SetParserProp(libxml2.PARSER_LOADDTD,1)
reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1)
@@ -98,12 +89,12 @@ while reader.Read() == 1:
res = res + "%s,%s\n" % (reader.NodeType(),reader.Name())
if res != expect:
- print("test2 failed: unexpected output")
- print(res)
+ print "test2 failed: unexpected output"
+ print res
sys.exit(1)
if err != "":
- print("test2 failed: validation error found")
- print(err)
+ print "test2 failed: validation error found"
+ print err
sys.exit(1)
#
@@ -133,12 +124,12 @@ res=""
def myResolver(URL, ID, ctxt):
if URL == "tst.ent":
- return(str_io(tst_ent))
+ return(StringIO.StringIO(tst_ent))
return None
libxml2.setEntityLoader(myResolver)
-input = libxml2.inputBuffer(str_io(s))
+input = libxml2.inputBuffer(StringIO.StringIO(s))
reader = input.newTextReader("test3")
reader.SetParserProp(libxml2.PARSER_LOADDTD,1)
reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1)
@@ -148,12 +139,12 @@ while reader.Read() == 1:
res = res + "%s %s\n" % (reader.NodeType(),reader.Name())
if res != expect:
- print("test3 failed: unexpected output")
- print(res)
+ print "test3 failed: unexpected output"
+ print res
sys.exit(1)
if err != "":
- print("test3 failed: validation error found")
- print(err)
+ print "test3 failed: validation error found"
+ print err
sys.exit(1)
#
@@ -192,7 +183,7 @@ expect="""10 test 0
res=""
err=""
-input = libxml2.inputBuffer(str_io(s))
+input = libxml2.inputBuffer(StringIO.StringIO(s))
reader = input.newTextReader("test4")
reader.SetParserProp(libxml2.PARSER_LOADDTD,1)
reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1)
@@ -202,12 +193,12 @@ while reader.Read() == 1:
res = res + "%s %s %d\n" % (reader.NodeType(),reader.Name(),reader.Depth())
if res != expect:
- print("test4 failed: unexpected output")
- print(res)
+ print "test4 failed: unexpected output"
+ print res
sys.exit(1)
if err != "":
- print("test4 failed: validation error found")
- print(err)
+ print "test4 failed: validation error found"
+ print err
sys.exit(1)
#
@@ -237,18 +228,18 @@ expect="""10 test 0
res=""
err=""
-input = libxml2.inputBuffer(str_io(s))
+input = libxml2.inputBuffer(StringIO.StringIO(s))
reader = input.newTextReader("test5")
reader.SetParserProp(libxml2.PARSER_VALIDATE,1)
while reader.Read() == 1:
res = res + "%s %s %d\n" % (reader.NodeType(),reader.Name(),reader.Depth())
if res != expect:
- print("test5 failed: unexpected output")
- print(res)
+ print "test5 failed: unexpected output"
+ print res
if err != "":
- print("test5 failed: validation error found")
- print(err)
+ print "test5 failed: validation error found"
+ print err
#
# cleanup
@@ -259,7 +250,7 @@ del reader
# Memory debug specific
libxml2.cleanupParser()
if libxml2.debugMemory(1) == 0:
- print("OK")
+ print "OK"
else:
- print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
+ print "Memory leak %d bytes" % (libxml2.debugMemory(1))
libxml2.dumpMemory()