| 1 | # regression test for SAX 2.0 -*- coding: iso-8859-1 -*- |
| 2 | # $Id: test_sax.py,v 1.27 2004/08/03 10:17:34 mwh Exp $ |
| 3 | |
| 4 | from xml.sax import make_parser, ContentHandler, \ |
| 5 | SAXException, SAXReaderNotAvailable, SAXParseException |
| 6 | try: |
| 7 | make_parser() |
| 8 | except SAXReaderNotAvailable: |
| 9 | # don't try to test this module if we cannot create a parser |
| 10 | raise ImportError("no XML parsers available") |
| 11 | from xml.sax.saxutils import XMLGenerator, escape, unescape, quoteattr, \ |
| 12 | XMLFilterBase |
| 13 | from xml.sax.expatreader import create_parser |
| 14 | from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl |
| 15 | from cStringIO import StringIO |
| 16 | from test.test_support import verify, verbose, TestFailed, findfile |
| 17 | import os |
| 18 | |
| 19 | # ===== Utilities |
| 20 | |
| 21 | tests = 0 |
| 22 | failures = [] |
| 23 | |
| 24 | def confirm(outcome, name): |
| 25 | global tests |
| 26 | |
| 27 | tests = tests + 1 |
| 28 | if outcome: |
| 29 | if verbose: |
| 30 | print "Passed", name |
| 31 | else: |
| 32 | failures.append(name) |
| 33 | |
| 34 | def test_make_parser2(): |
| 35 | try: |
| 36 | # Creating parsers several times in a row should succeed. |
| 37 | # Testing this because there have been failures of this kind |
| 38 | # before. |
| 39 | from xml.sax import make_parser |
| 40 | p = make_parser() |
| 41 | from xml.sax import make_parser |
| 42 | p = make_parser() |
| 43 | from xml.sax import make_parser |
| 44 | p = make_parser() |
| 45 | from xml.sax import make_parser |
| 46 | p = make_parser() |
| 47 | from xml.sax import make_parser |
| 48 | p = make_parser() |
| 49 | from xml.sax import make_parser |
| 50 | p = make_parser() |
| 51 | except: |
| 52 | return 0 |
| 53 | else: |
| 54 | return p |
| 55 | |
| 56 | |
| 57 | # =========================================================================== |
| 58 | # |
| 59 | # saxutils tests |
| 60 | # |
| 61 | # =========================================================================== |
| 62 | |
| 63 | # ===== escape |
| 64 | |
| 65 | def test_escape_basic(): |
| 66 | return escape("Donald Duck & Co") == "Donald Duck & Co" |
| 67 | |
| 68 | def test_escape_all(): |
| 69 | return escape("<Donald Duck & Co>") == "<Donald Duck & Co>" |
| 70 | |
| 71 | def test_escape_extra(): |
| 72 |