]> granicus.if.org Git - python/commitdiff
Add a test case for reporting the file name, and for reporting an error
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 6 Oct 2000 21:13:23 +0000 (21:13 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 6 Oct 2000 21:13:23 +0000 (21:13 +0000)
for incomplete input.

Lib/test/output/test_sax
Lib/test/test_sax.py

index d2ccf889bfe45ef2d5c3ff767aad73db054f0e1e..3667e81bbe36f5e57fe5f21800ad3a04e19f138d 100644 (file)
@@ -8,7 +8,9 @@ Passed test_expat_attrs_empty
 Passed test_expat_attrs_wattr
 Passed test_expat_dtdhandler
 Passed test_expat_entityresolver
+Passed test_expat_incomplete
 Passed test_expat_inpsource_filename
+Passed test_expat_inpsource_location
 Passed test_expat_inpsource_stream
 Passed test_expat_inpsource_sysid
 Passed test_expat_nsattrs_empty
@@ -23,4 +25,4 @@ Passed test_xmlgen_content_escape
 Passed test_xmlgen_ignorable
 Passed test_xmlgen_ns
 Passed test_xmlgen_pi
-24 tests, 0 failures
+26 tests, 0 failures
index b3576ab1c8546251f6c4152b727505e7a3bedb66..e080217c06a42e025aefdc56c543af2d55396cd2 100644 (file)
@@ -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