[Zope-Checkins] CVS: Zope/lib/python/Products/ZCTextIndex/tests - testLexicon.py:1.3.42.1

Casey Duncan casey@zope.com
Mon, 2 Dec 2002 00:04:46 -0500


Update of /cvs-repository/Zope/lib/python/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv5405/tests

Modified Files:
      Tag: casey-zctextindex-locale-branch
	testLexicon.py 
Log Message:
Added locale support to splitters and a unit test as per collector #597


=== Zope/lib/python/Products/ZCTextIndex/tests/testLexicon.py 1.3 => 1.3.42.1 ===
--- Zope/lib/python/Products/ZCTextIndex/tests/testLexicon.py:1.3	Thu May 16 15:51:12 2002
+++ Zope/lib/python/Products/ZCTextIndex/tests/testLexicon.py	Mon Dec  2 00:04:46 2002
@@ -12,6 +12,7 @@
 #
 ##############################################################################
 
+import sys
 from unittest import TestCase, TestSuite, main, makeSuite
 
 from Products.ZCTextIndex.Lexicon import Lexicon
@@ -112,7 +113,24 @@
         wids = lexicon.sourceToWordIds('cats and dogs')
         wids = lexicon.termToWordIds('hsif')
         self.assertEqual(wids, [2])
-
+        
+    def testSplitterLocaleAwareness(self):
+        from Products.ZCTextIndex.HTMLSplitter import HTMLWordSplitter
+        import locale
+        loc = locale.setlocale(locale.LC_ALL) # get current locale
+         # set German locale
+        if sys.platform != 'win32':
+            locale.setlocale(locale.LC_ALL, 'de_DE.ISO8859-1')
+        else:
+            locale.setlocale(locale.LC_ALL, 'German_Germany.1252')
+        words = ['mülltonne waschbär behörde überflieger']
+        words = Splitter().process(words)
+        self.assertEqual(
+            words, ['mülltonne', 'waschbär', 'behörde', 'überflieger'])
+        words = HTMLWordSplitter().process(words)
+        self.assertEqual(
+            words, ['mülltonne', 'waschbär', 'behörde', 'überflieger'])        
+        locale.setlocale(locale.LC_ALL, loc) # restore saved locale
 
 def test_suite():
     return makeSuite(Test)