mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
Updated Python test reader2.py
Added all test cases that have a non-empty error in result/valid/*.xml.err Restructured to make it easier extensible with new test cases Added coding cookie because there is non-ASCII in the error messages
This commit is contained in:
committed by
Nick Wellnhofer
parent
8c3e52ebd9
commit
8f62ac92b2
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/python -u
|
#!/usr/bin/python -u
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# this tests the DTD validation with the XmlTextReader interface
|
# this tests the DTD validation with the XmlTextReader interface
|
||||||
#
|
#
|
||||||
@@ -17,43 +18,130 @@ except:
|
|||||||
libxml2.debugMemory(1)
|
libxml2.debugMemory(1)
|
||||||
|
|
||||||
err = ""
|
err = ""
|
||||||
expect="""../../test/valid/rss.xml:177: element rss: validity error : Element rss does not carry attribute version
|
dir_prefix = "../../test/valid/"
|
||||||
</rss>
|
# This dictionary reflects the contents of the files
|
||||||
|
# ../../test/valid/*.xml.err that are not empty, except that
|
||||||
|
# the file paths in the messages start with ../../test/
|
||||||
|
|
||||||
|
expect = {
|
||||||
|
'766956':
|
||||||
|
"""../../test/valid/dtds/766956.dtd:2: parser error : PEReference: expecting ';'
|
||||||
|
%ä%ent;
|
||||||
^
|
^
|
||||||
../../test/valid/xlink.xml:450: element termdef: validity error : ID dt-arc already defined
|
../../test/valid/dtds/766956.dtd:2: parser error : Content error in the external subset
|
||||||
<p><termdef id="dt-arc" term="Arc">An <ter
|
%ä%ent;
|
||||||
^
|
^
|
||||||
../../test/valid/xlink.xml:530: validity error : attribute def line 199 references an unknown ID "dt-xlg"
|
Entity: line 1:
|
||||||
|
value
|
||||||
|
^
|
||||||
|
""",
|
||||||
|
'781333':
|
||||||
|
"""../../test/valid/781333.xml:4: element a: validity error : Element a content does not follow the DTD, expecting ( ..., got
|
||||||
|
<a/>
|
||||||
|
^
|
||||||
|
../../test/valid/781333.xml:5: element a: validity error : Element a content does not follow the DTD, Expecting more child
|
||||||
|
|
||||||
^
|
^
|
||||||
"""
|
""",
|
||||||
|
'cond_sect2':
|
||||||
|
"""../../test/valid/dtds/cond_sect2.dtd:15: parser error : All markup of the conditional section is not in the same entity
|
||||||
|
%ent;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
]]>
|
||||||
|
^
|
||||||
|
../../test/valid/dtds/cond_sect2.dtd:17: parser error : Content error in the external subset
|
||||||
|
|
||||||
|
^
|
||||||
|
""",
|
||||||
|
'rss':
|
||||||
|
"""../../test/valid/rss.xml:177: element rss: validity error : Element rss does not carry attribute version
|
||||||
|
</rss>
|
||||||
|
^
|
||||||
|
""",
|
||||||
|
't8':
|
||||||
|
"""../../test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot; %defmiddle; %deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT root (middle) >
|
||||||
|
^
|
||||||
|
../../test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot; %defmiddle; %deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT middle (test) >
|
||||||
|
^
|
||||||
|
../../test/valid/t8.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot; %defmiddle; %deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT test (#PCDATA) >
|
||||||
|
^
|
||||||
|
""",
|
||||||
|
't8a':
|
||||||
|
"""../../test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot;%defmiddle;%deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT root (middle) >
|
||||||
|
^
|
||||||
|
../../test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot;%defmiddle;%deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT middle (test) >
|
||||||
|
^
|
||||||
|
../../test/valid/t8a.xml:6: parser error : internal error: xmlParseInternalSubset: error detected in Markup declaration
|
||||||
|
|
||||||
|
%defroot;%defmiddle;%deftest;
|
||||||
|
^
|
||||||
|
Entity: line 1:
|
||||||
|
<!ELEMENT test (#PCDATA) >
|
||||||
|
^
|
||||||
|
""",
|
||||||
|
'xlink':
|
||||||
|
"""../../test/valid/xlink.xml:450: element termdef: validity error : ID dt-arc already defined
|
||||||
|
<p><termdef id="dt-arc" term="Arc">An <ter
|
||||||
|
^
|
||||||
|
validity error : attribute def line 199 references an unknown ID "dt-xlg"
|
||||||
|
""",
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add prefix_dir and extension to the keys
|
||||||
|
expect = {"{}{}.xml".format(dir_prefix, key): val for key, val in expect.items()}
|
||||||
|
|
||||||
def callback(ctx, str):
|
def callback(ctx, str):
|
||||||
global err
|
global err
|
||||||
err = err + "%s" % (str)
|
err = err + "%s" % (str)
|
||||||
libxml2.registerErrorHandler(callback, "")
|
libxml2.registerErrorHandler(callback, "")
|
||||||
|
|
||||||
valid_files = glob.glob("../../test/valid/*.x*")
|
parsing_error_files = ["766956", "cond_sect2", "t8", "t8a"]
|
||||||
|
expect_parsing_error = ["{}{}.xml".format(dir_prefix, f) for f in parsing_error_files]
|
||||||
|
|
||||||
|
valid_files = glob.glob(dir_prefix + "*.x*")
|
||||||
valid_files.sort()
|
valid_files.sort()
|
||||||
for file in valid_files:
|
for file in valid_files:
|
||||||
if file.find("t8") != -1:
|
err = ""
|
||||||
continue
|
|
||||||
if file == "../../test/valid/rss.xml":
|
|
||||||
continue
|
|
||||||
if file == "../../test/valid/xlink.xml":
|
|
||||||
continue
|
|
||||||
reader = libxml2.newTextReaderFilename(file)
|
reader = libxml2.newTextReaderFilename(file)
|
||||||
#print "%s:" % (file)
|
#print "%s:" % (file)
|
||||||
reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
|
reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
|
||||||
ret = reader.Read()
|
ret = reader.Read()
|
||||||
while ret == 1:
|
while ret == 1:
|
||||||
ret = reader.Read()
|
ret = reader.Read()
|
||||||
if ret != 0:
|
if ret != 0 and file not in expect_parsing_error:
|
||||||
print("Error parsing and validating %s" % (file))
|
print("Error parsing and validating %s" % (file))
|
||||||
#sys.exit(1)
|
#sys.exit(1)
|
||||||
|
if (err):
|
||||||
if err != expect:
|
if not(file in expect and err == expect[file]):
|
||||||
print(err)
|
print("Error: ", err)
|
||||||
|
if file in expect:
|
||||||
|
print("Expected: ", expect[file])
|
||||||
#
|
#
|
||||||
# another separate test based on Stephane Bidoul one
|
# another separate test based on Stephane Bidoul one
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user