[Zope-CVS] CVS: Products/ZCTextIndex/tests - testLexicon.py:1.1.2.5

Barry Warsaw barry@wooz.org
Wed, 1 May 2002 12:36:10 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv4457/tests

Modified Files:
      Tag: TextIndexDS9-branch
	testLexicon.py 
Log Message:
An interface and implementation for splitters (but all the fun is in
the constructors).

Modify the tests to use the ISplitter interface.


=== Products/ZCTextIndex/tests/testLexicon.py 1.1.2.4 => 1.1.2.5 ===
 
 from Products.ZCTextIndex.Lexicon import Lexicon
+from Products.ZCTextIndex.Splitter import Splitter
 from Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter.ZopeSplitter \
      import ZopeSplitter
 
@@ -66,54 +67,45 @@
         return res
 
 
-class SplitterAdaptor:
-    def __init__(self, splitterclass, casefolding=0):
-        self.__class = splitterclass
-        self.__casefolding = casefolding
-
-    def __call__(self, text):
-        return self.__class(text, casefolding=self.__casefolding)
-
-
 class Test(TestCase):
     def testSourceToWordIds(self):
-        lexicon = Lexicon(ZopeSplitter)
+        lexicon = Lexicon(Splitter(ZopeSplitter))
         wids = lexicon.sourceToWordIds('cats and dogs')
         self.assertEqual(wids, [1, 2, 3])
 
     def testTermToWordIds(self):
-        lexicon = Lexicon(ZopeSplitter)
+        lexicon = Lexicon(Splitter(ZopeSplitter))
         wids = lexicon.sourceToWordIds('cats and dogs')
         wids = lexicon.termToWordIds('dogs')
         self.assertEqual(wids, [3])
 
     def testMissingTermToWordIds(self):
-        lexicon = Lexicon(ZopeSplitter)
+        lexicon = Lexicon(Splitter(ZopeSplitter))
         wids = lexicon.sourceToWordIds('cats and dogs')
         wids = lexicon.termToWordIds('boxes')
         self.assertEqual(wids, [])
 
     def testOnePipelineElement(self):
-        lexicon = Lexicon(ZopeSplitter,
+        lexicon = Lexicon(Splitter(ZopeSplitter),
                           (StupidPipelineElement('dogs', 'fish'),),)
         wids = lexicon.sourceToWordIds('cats and dogs')
         wids = lexicon.termToWordIds('fish')
         self.assertEqual(wids, [3])
 
     def testSplitterAdaptorFold(self):
-        lexicon = Lexicon(SplitterAdaptor(ZopeSplitter, casefolding=1))
+        lexicon = Lexicon(Splitter(ZopeSplitter, casefolding=1))
         wids = lexicon.sourceToWordIds('CATS and dogs')
         wids = lexicon.termToWordIds('cats and dogs')
         self.assertEqual(wids, [1, 2, 3])
 
     def testSplitterAdaptorNofold(self):
-        lexicon = Lexicon(SplitterAdaptor(ZopeSplitter))
+        lexicon = Lexicon(Splitter(ZopeSplitter, casefolding=0))
         wids = lexicon.sourceToWordIds('CATS and dogs')
         wids = lexicon.termToWordIds('cats and dogs')
         self.assertEqual(wids, [2, 3])
 
     def testTwoElementPipeline(self):
-        lexicon = Lexicon(ZopeSplitter,
+        lexicon = Lexicon(Splitter(ZopeSplitter),
                           (StupidPipelineElement('cats', 'fish'),
                            WackyReversePipelineElement('fish')))
         wids = lexicon.sourceToWordIds('cats and dogs')
@@ -121,7 +113,7 @@
         self.assertEqual(wids, [1])
 
     def testThreeElementPipeline(self):
-        lexicon = Lexicon(ZopeSplitter,
+        lexicon = Lexicon(Splitter(ZopeSplitter),
                           (StopWordPipelineElement({'and':1}),
                            StupidPipelineElement('dogs', 'fish'),
                            WackyReversePipelineElement('fish')))