]> granicus.if.org Git - python/commitdiff
include at least one example of an exception passing through pyexpat
authorFred Drake <fdrake@acm.org>
Fri, 13 Aug 2004 03:09:07 +0000 (03:09 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 13 Aug 2004 03:09:07 +0000 (03:09 +0000)
Lib/test/test_pyexpat.py

index f281f8baad4aef32d5747cff22e9e9cf089955b2..44f9ee8e9b44974a12d72f832d0bd5d0bf8fd153 100644 (file)
@@ -311,3 +311,18 @@ parser.Parse("<a>1<b/>2<c></c>3<!--abc-->4<!--def-->5</a> ", 1)
 handler.check(["<a>", "1", "<b>", "</b>", "2", "<c>", "</c>", "3",
                "<!--abc-->", "4", "<!--def-->", "5", "</a>"],
               "buffered text not properly split")
+
+# Test handling of exception from callback:
+def StartElementHandler(name, attrs):
+    raise RuntimeError(name)
+
+parser = expat.ParserCreate()
+parser.StartElementHandler = StartElementHandler
+
+try:
+    parser.Parse("<a><b><c/></b></a>", 1)
+except RuntimeError, e:
+    if e.args[0] != "a":
+        print "Expected RuntimeError for element 'a'; found %r" % e.args[0]
+else:
+    print "Expected RuntimeError for 'a'"