File: test_expatreader.py

package info (click to toggle)
python-xml 0.8.4-10.1%2Blenny1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 4,972 kB
  • ctags: 10,628
  • sloc: python: 46,730; ansic: 14,354; xml: 968; makefile: 201; sh: 20
file content (44 lines) | stat: -rw-r--r-- 1,174 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Test specific to the Expat SAX handler

# Check presence of underlying parser
try:
    import xml.parsers.expat
except ImportError:
    import pyexpat

from xml.sax.expatreader import create_parser
from xml.sax import handler
from xml.sax import SAXNotSupportedException
import test_support
import unittest

testcases = []

class feature_namespace_prefixes(unittest.TestCase):
    def setUp(self):
        self.parser = create_parser()
        self.parser.setFeature(handler.feature_namespaces, 1)
        self.parser.setFeature(handler.feature_namespace_prefixes, 1)

    def test_prefix_given(self):
        class Handler(handler.ContentHandler):
            def startElementNS(self, name, qname, attrs):
                self.qname = qname

        h = Handler()

        self.parser.setContentHandler(h)
        self.parser.feed("<Q:E xmlns:Q='http://pyxml.sf.net/testuri'/>")
        self.parser.close()
        self.failIf(h.qname is None)

testcases.append(feature_namespace_prefixes)

def test_main():
    import test_support
    test_support.run_unittest(*testcases)

if __name__ == "__main__":
    import test_support
    test_support.verbose = 1
    test_main()