mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-20 18:50:08 +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:
parent
8c3e52ebd9
commit
8f62ac92b2
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python -u
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# this tests the DTD validation with the XmlTextReader interface
|
||||
#
|
||||
@ -16,44 +17,131 @@ except:
|
||||
# Memory debug specific
|
||||
libxml2.debugMemory(1)
|
||||
|
||||
err=""
|
||||
expect="""../../test/valid/rss.xml:177: element rss: validity error : Element rss does not carry attribute version
|
||||
</rss>
|
||||
^
|
||||
../../test/valid/xlink.xml:450: element termdef: validity error : ID dt-arc already defined
|
||||
<p><termdef id="dt-arc" term="Arc">An <ter
|
||||
^
|
||||
../../test/valid/xlink.xml:530: validity error : attribute def line 199 references an unknown ID "dt-xlg"
|
||||
err = ""
|
||||
dir_prefix = "../../test/valid/"
|
||||
# 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/dtds/766956.dtd:2: parser error : Content error in the external subset
|
||||
%ä%ent;
|
||||
^
|
||||
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):
|
||||
global err
|
||||
err = err + "%s" % (str)
|
||||
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()
|
||||
for file in valid_files:
|
||||
if file.find("t8") != -1:
|
||||
continue
|
||||
if file == "../../test/valid/rss.xml":
|
||||
continue
|
||||
if file == "../../test/valid/xlink.xml":
|
||||
continue
|
||||
err = ""
|
||||
reader = libxml2.newTextReaderFilename(file)
|
||||
#print "%s:" % (file)
|
||||
reader.SetParserProp(libxml2.PARSER_VALIDATE, 1)
|
||||
ret = reader.Read()
|
||||
while ret == 1:
|
||||
ret = reader.Read()
|
||||
if ret != 0:
|
||||
if ret != 0 and file not in expect_parsing_error:
|
||||
print("Error parsing and validating %s" % (file))
|
||||
#sys.exit(1)
|
||||
|
||||
if err != expect:
|
||||
print(err)
|
||||
|
||||
#sys.exit(1)
|
||||
if (err):
|
||||
if not(file in expect and err == expect[file]):
|
||||
print("Error: ", err)
|
||||
if file in expect:
|
||||
print("Expected: ", expect[file])
|
||||
#
|
||||
# another separate test based on Stephane Bidoul one
|
||||
#
|
||||
|
Loading…
x
Reference in New Issue
Block a user