From 2fc5294911b808c002b2197c086528ed08cb6d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gust=C3=A4bel?= Date: Tue, 24 Oct 2000 15:35:07 +0000 Subject: [PATCH] Added some more tests here and there. --- Lib/test/test_sax.py | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 26fd87344ec..59e14c5ef37 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -29,6 +29,29 @@ def confirm(outcome, name): print "Failed", name fails = fails + 1 +def test_make_parser2(): + try: + # Creating parsers several times in a row should succeed. + # Testing this because there have been failures of this kind + # before. + from xml.sax import make_parser + p = make_parser() + from xml.sax import make_parser + p = make_parser() + from xml.sax import make_parser + p = make_parser() + from xml.sax import make_parser + p = make_parser() + from xml.sax import make_parser + p = make_parser() + from xml.sax import make_parser + p = make_parser() + except: + return 0 + else: + return p + + # =========================================================================== # # saxutils tests @@ -313,6 +336,67 @@ def test_expat_inpsource_stream(): return result.getvalue() == xml_test_out +# ===== IncrementalParser support + +def test_expat_incremental(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + parser.feed("") + parser.feed("") + parser.close() + + return result.getvalue() == start + "" + +def test_expat_incremental_reset(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + parser.feed("") + parser.feed("text") + + result = StringIO() + xmlgen = XMLGenerator(result) + parser.setContentHandler(xmlgen) + parser.reset() + + parser.feed("") + parser.feed("text") + parser.feed("") + parser.close() + + return result.getvalue() == start + "text" + +# ===== Locator support + +def test_expat_locator_noinfo(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + parser.feed("") + parser.feed("") + parser.close() + + return parser.getSystemId() == None and \ + parser.getPublicId() == None and \ + parser.getLineNumber() == 1 + +def test_expat_locator_withinfo(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + parser.parse(findfile("test.xml")) + + return parser.getSystemId() == findfile("test.xml") and \ + parser.getPublicId() == None + # =========================================================================== #