summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sax.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2000-10-06 21:13:23 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2000-10-06 21:13:23 (GMT)
commit80670bcabaf071bfe9131f3907b44632a672f9cb (patch)
tree22c260c276cd483272defb8bf19a16750485127c /Lib/test/test_sax.py
parent31b485ffb0572fb1e71ee7ab6fb4a641a4710870 (diff)
downloadcpython-80670bcabaf071bfe9131f3907b44632a672f9cb.zip
cpython-80670bcabaf071bfe9131f3907b44632a672f9cb.tar.gz
cpython-80670bcabaf071bfe9131f3907b44632a672f9cb.tar.bz2
Add a test case for reporting the file name, and for reporting an error
for incomplete input.
Diffstat (limited to 'Lib/test/test_sax.py')
-rw-r--r--Lib/test/test_sax.py35
1 files changed, 33 insertions, 2 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index b3576ab..e080217 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -2,10 +2,11 @@
# regression test for SAX 2.0
# $Id$
-from xml.sax import make_parser, ContentHandler
+from xml.sax import make_parser, ContentHandler, \
+ SAXException, SAXReaderNotAvailable, SAXParseException
try:
make_parser()
-except xml.sax.SAXReaderNotAvailable:
+except SAXReaderNotAvailable:
# don't try to test this module if we cannot create a parser
raise ImportError("no XML parsers available")
from xml.sax.saxutils import XMLGenerator, escape, XMLFilterBase
@@ -313,6 +314,36 @@ def test_expat_inpsource_stream():
return result.getvalue() == xml_test_out
+
+# ===========================================================================
+#
+# error reporting
+#
+# ===========================================================================
+
+def test_expat_inpsource_location():
+ parser = create_parser()
+ parser.setContentHandler(ContentHandler()) # do nothing
+ source = InputSource()
+ source.setByteStream(StringIO("<foo bar foobar>")) #ill-formed
+ name = "a file name"
+ source.setSystemId(name)
+ try:
+ parser.parse(source)
+ except SAXException, e:
+ return e.getSystemId() == name
+
+def test_expat_incomplete():
+ parser = create_parser()
+ parser.setContentHandler(ContentHandler()) # do nothing
+ try:
+ parser.parse(StringIO("<foo>"))
+ except SAXParseException:
+ return 1 # ok, error found
+ else:
+ return 0
+
+
# ===========================================================================
#
# xmlreader tests