summaryrefslogtreecommitdiff
path: root/src/lxml/tests/test_xmlschema.py
diff options
context:
space:
mode:
authorscoder <none@none>2008-03-23 18:49:42 +0100
committerscoder <none@none>2008-03-23 18:49:42 +0100
commit7aa617f81148e80130bf9d13406f1906f286c877 (patch)
tree5e90ed7eeba7b442573812be29881e0e23c31f5b /src/lxml/tests/test_xmlschema.py
parent86c76be05c5a973ec3979ca621ffa6464891615e (diff)
downloadpython-lxml-7aa617f81148e80130bf9d13406f1906f286c877.tar.gz
[svn r3452] r3820@delle: sbehnel | 2008-03-23 18:48:28 +0100
fix for iterparse crash with XML schema validation --HG-- branch : trunk
Diffstat (limited to 'src/lxml/tests/test_xmlschema.py')
-rw-r--r--src/lxml/tests/test_xmlschema.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lxml/tests/test_xmlschema.py b/src/lxml/tests/test_xmlschema.py
index 0da31697..364fa839 100644
--- a/src/lxml/tests/test_xmlschema.py
+++ b/src/lxml/tests/test_xmlschema.py
@@ -66,6 +66,41 @@ class ETreeXMLSchemaTestCase(HelperTestCase):
self.assertRaises(etree.XMLSyntaxError,
self.parse, '<a><c></c></a>', parser=parser)
+ def test_xmlschema_iterparse(self):
+ schema = self.parse('''
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:element name="a" type="AType"/>
+ <xsd:complexType name="AType">
+ <xsd:sequence>
+ <xsd:element name="b" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+</xsd:schema>
+''')
+ schema = etree.XMLSchema(schema)
+ xml = StringIO('<a><b></b></a>')
+ events = [ (event, el.tag)
+ for (event, el) in etree.iterparse(xml, schema=schema) ]
+
+ self.assertEquals([('end', 'b'), ('end', 'a')],
+ events)
+
+ def test_xmlschema_iterparse_fail(self):
+ schema = self.parse('''
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:element name="a" type="AType"/>
+ <xsd:complexType name="AType">
+ <xsd:sequence>
+ <xsd:element name="b" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+</xsd:schema>
+''')
+ schema = etree.XMLSchema(schema)
+ self.assertRaises(
+ etree.XMLSyntaxError,
+ list, etree.iterparse(StringIO('<a><c></c></a>'), schema=schema))
+
def test_xmlschema_elementtree_error(self):
self.assertRaises(ValueError, etree.XMLSchema, etree.ElementTree())