diff options
-rw-r--r-- | Lib/test/test_sax.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 26fd873..59e14c5 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("<doc>") + parser.feed("</doc>") + parser.close() + + return result.getvalue() == start + "<doc></doc>" + +def test_expat_incremental_reset(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + parser.feed("<doc>") + parser.feed("text") + + result = StringIO() + xmlgen = XMLGenerator(result) + parser.setContentHandler(xmlgen) + parser.reset() + + parser.feed("<doc>") + parser.feed("text") + parser.feed("</doc>") + parser.close() + + return result.getvalue() == start + "<doc>text</doc>" + +# ===== Locator support + +def test_expat_locator_noinfo(): + result = StringIO() + xmlgen = XMLGenerator(result) + parser = create_parser() + parser.setContentHandler(xmlgen) + + parser.feed("<doc>") + parser.feed("</doc>") + 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 + # =========================================================================== # |