[ZPT] CVS: Zope/lib/python/TAL/tests - test_xmlparser.py:1.4.32.1 utils.py:1.4.32.1

Chris Withers chrisw@nipltd.com
Tue, 14 May 2002 05:33:48 -0400


Update of /cvs-repository/Zope/lib/python/TAL/tests
In directory cvs.zope.org:/tmp/cvs-serv15607

Modified Files:
      Tag: Zope-2_5-branch
	test_xmlparser.py utils.py 
Log Message:
Merge fix for dodgy test to 2.5 branch.

=== Zope/lib/python/TAL/tests/test_xmlparser.py 1.4 => 1.4.32.1 ===
         else:
             parser.parseString(source)
-        self.assert_(parser.get_events() == events, parser.get_events())
+        if utils.oldexpat:
+            while events[0][0] in ('decl', 'doctype'):
+                del events[0]
+        self.assertEquals(parser.get_events(), events)
 
     def _run_check_extra(self, source, events):
         self._run_check(source, events, EventCollectorExtra)


=== Zope/lib/python/TAL/tests/utils.py 1.4 => 1.4.32.1 ===
 
 # Set skipxml to true if an XML parser could not be found.
+pyexpat = None
 skipxml = 0
 try:
     import pyexpat
@@ -22,7 +23,22 @@
         import xml.parsers.pyexpat
     except ImportError:
         skipxml = 1
+    else:
+        pyexpat = xml.parsers.pyexpat
 
+# Set oldexpat if the StartDoctypeDeclHandler and XmlDeclHandler are
+# not supported.  The tests need to know whether the events reported
+# by those handlers should be expected, but need to make sure the
+# right thing is returned if they are.
+oldexpat = 0
+if pyexpat is not None:
+    p = pyexpat.ParserCreate()
+    # Can't use hasattr() since pyexpat supports the handler
+    # attributes in a broken way.
+    try:
+        p.StartDoctypeDeclHandler = None
+    except AttributeError:
+        oldexpat = 1
 
 def run_suite(suite, outf=None, errf=None):
     if outf is None: