[ZPT] CVS: Zope3/lib/python/Zope/TAL/tests - test_files.py:1.5.14.2 test_htmltalparser.py:1.25.14.2 test_xmlparser.py:1.4.14.2

Martijn Pieters mj@zope.com
Wed, 13 Feb 2002 00:03:41 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	test_files.py test_htmltalparser.py test_xmlparser.py 
Log Message:
Optimizations and code style updates:

  - Use isinstance on type checks

  - Test UnicodeType and StringType through StringTypes

  - Remove use of the string module

  - Use startswith and endswith instead of slices.

  - Fix weird tests where isinstance suffices.


=== Zope3/lib/python/Zope/TAL/tests/test_files.py 1.5.14.1 => 1.5.14.2 ===
         #sys.stdout.write(basename + " ")
         sys.stdout.flush()
-        if basename[:10] == 'test_metal':
+        if basename.startswith('test_metal'):
             sys.argv = ["", "-Q", "-m", self.__file]
         else:
             sys.argv = ["", "-Q", self.__file]


=== Zope3/lib/python/Zope/TAL/tests/test_htmltalparser.py 1.25.14.1 => 1.25.14.2 ===
 import unittest
 
-from string import rfind
 
 from Zope.TAL import HTMLTALParser
 from Zope.TAL.TALDefs import TAL_VERSION, TALError, METALError
@@ -24,7 +23,7 @@
         if p1 and p2:
             op1, args1 = p1[-1]
             op2, args2 = p2[0]
-            if op1[:7] == 'rawtext' and op2[:7] == 'rawtext':
+            if op1.startswith('rawtext') and op2.startswith('rawtext'):
                 return (p1[:-1]
                         + [rawtext(args1[0] + args2[0])]
                         + p2[1:])
@@ -60,7 +59,7 @@
 def rawtext(s):
     """Compile raw text to the appropriate instruction."""
     if "\n" in s:
-        return ("rawtextColumn", (s, len(s) - (rfind(s, "\n") + 1)))
+        return ("rawtextColumn", (s, len(s) - (s.rfind("\n") + 1)))
     else:
         return ("rawtextOffset", (s, len(s)))
 


=== Zope3/lib/python/Zope/TAL/tests/test_xmlparser.py 1.4.14.1 => 1.4.14.2 ===
 """Tests for XMLParser.py."""
 
-import string
 import sys
+from types import ListType
 
 from Zope.TAL.tests import utils
 import unittest
@@ -88,7 +88,7 @@
 
     def _run_check(self, source, events, collector=EventCollector):
         parser = collector()
-        if isinstance(source, type([])):
+        if isinstance(source, ListType):
             parser.parseStream(SegmentedFile(source))
         else:
             parser.parseString(source)