[Python-checkins] python/dist/src/Lib/test test_sax.py,1.19.8.1,1.19.8.2

fdrake@users.sourceforge.net fdrake@users.sourceforge.net
Tue, 08 Oct 2002 12:49:38 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv17520/Lib/test

Modified Files:
      Tag: release22-maint
	test_sax.py 
Log Message:
Fix some code that was added to the r22-maint branch to allow it to work with
arbitrary versions of Expat.
Not applicable to Python 2.3, which will incorporate an Expat that does not
need this crutch.


Index: test_sax.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_sax.py,v
retrieving revision 1.19.8.1
retrieving revision 1.19.8.2
diff -C2 -d -r1.19.8.1 -r1.19.8.2
*** test_sax.py	26 Sep 2002 15:24:41 -0000	1.19.8.1
--- test_sax.py	8 Oct 2002 19:49:35 -0000	1.19.8.2
***************
*** 349,352 ****
--- 349,416 ----
             attrs[(ns_uri, "attr")] == "val"
  
+ class ElemGatherer(ContentHandler):
+     def __init__(self):
+         self.events = []
+     def startElementNS(self, pair, qname, attrs):
+         self.events.append(('start', pair, qname))
+     def endElementNS(self, pair, qname):
+         self.events.append(('end', pair, qname))
+ 
+ def check_expat_nsdecl(text, expected):
+     parser = create_parser(1)
+     handler = ElemGatherer()
+     parser.setContentHandler(handler)
+     parser.feed(text)
+     parser.close()
+     if verbose and handler.events != expected:
+         from pprint import pprint
+         print "Expected:"
+         pprint(expected)
+         print "Received:"
+         pprint(handler.events)
+     return handler.events == expected
+ 
+ def test_expat_nsdecl_single():
+     return check_expat_nsdecl(
+         "<abc xmlns='http://xml.python.org/'></abc>", [
+             ("start", ("http://xml.python.org/", "abc"), "abc"),
+             ("end", ("http://xml.python.org/", "abc"), "abc"),
+             ])
+ 
+ def test_expat_nsdecl_pair_same():
+     # XXX This shows where xml.sax.expatreader can use the wrong
+     # prefix when more than one is in scope for a particular URI.
+     # We still want to exercise this code since previous versions got
+     # the namespace handling wrong in more severe ways (exceptions
+     # that should not have happened).
+     return check_expat_nsdecl(
+         "<abc xmlns='http://xml.python.org/'"
+         "     xmlns:foo='http://xml.python.org/'>"
+         "<foo:def/>"
+         "<ghi/>"
+         "</abc>", [
+             ("start", ("http://xml.python.org/", "abc"), "foo:abc"),
+             ("start", ("http://xml.python.org/", "def"), "foo:def"),
+             ("end", ("http://xml.python.org/", "def"), "foo:def"),
+             ("start", ("http://xml.python.org/", "ghi"), "foo:ghi"),
+             ("end", ("http://xml.python.org/", "ghi"), "foo:ghi"),
+             ("end", ("http://xml.python.org/", "abc"), "foo:abc"),
+             ])
+ 
+ def test_expat_nsdecl_pair_diff():
+     return check_expat_nsdecl(
+         "<abc xmlns='http://xml.python.org/1'"
+         "     xmlns:foo='http://xml.python.org/2'>"
+         "<foo:def/>"
+         "<ghi/>"
+         "</abc>", [
+             ("start", ("http://xml.python.org/1", "abc"), "abc"),
+             ("start", ("http://xml.python.org/2", "def"), "foo:def"),
+             ("end", ("http://xml.python.org/2", "def"), "foo:def"),
+             ("start", ("http://xml.python.org/1", "ghi"), "ghi"),
+             ("end", ("http://xml.python.org/1", "ghi"), "ghi"),
+             ("end", ("http://xml.python.org/1", "abc"), "abc"),
+             ])
+ 
  # ===== InputSource support