[Zope-CVS] CVS: Products/ZCTextIndex/tests - testLexicon.py:1.1.2.2
Barry Warsaw
barry@wooz.org
Wed, 1 May 2002 11:26:08 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv28862
Modified Files:
Tag: TextIndexDS9-branch
testLexicon.py
Log Message:
A few more tests: test a pipeline with actual elements in it (well,
one for now), and test a splitter which adapts from the ZopeSplitter
API to the ILexicon API.
=== Products/ZCTextIndex/tests/testLexicon.py 1.1.2.1 => 1.1.2.2 ===
import ZopeSplitter
-##class StupidPipelineElement:
-## def __init__(self, fromword, toword):
-## self.__fromword = fromword
-## self.__toword = toword
+class StupidPipelineElement:
+ def __init__(self, fromword, toword):
+ self.__fromword = fromword
+ self.__toword = toword
+
+ def __call__(self, seq):
+ res = []
+ for term in seq:
+ if term == self.__fromword:
+ res.append(self.__toword)
+ else:
+ res.append(term)
+ return res
+
+
+class SplitterAdaptor:
+ def __init__(self, splitterclass, synstop=None, casefolding=0):
+ self.__class = splitterclass
+ self.__synstop = synstop
+ self.__casefolding = casefolding
+
+ def __call__(self, text):
+ return self.__class(text,
+ synstop=self.__synstop,
+ casefolding=self.__casefolding)
-## def __call__(self, seq):
-## seq.replace(self.__fromword, self.__toword)
class Test(TestCase):
def testSourceToWordIds(self):
@@ -49,11 +68,31 @@
wids = lexicon.termToWordIds('boxes')
self.assertEqual(wids, [])
+ def testStupidPipelineElement(self):
+ lexicon = Lexicon(ZopeSplitter,
+ (StupidPipelineElement('dogs', 'fish'),),)
+ wids = lexicon.sourceToWordIds('cats and dogs')
+ wids = lexicon.termToWordIds('fish')
+ self.assertEqual(wids, [3])
+
+ def testBiggerPipeline(self):
+ lexicon = Lexicon(SplitterAdaptor(ZopeSplitter, casefolding=1))
+ wids = lexicon.sourceToWordIds('CATS and dogs')
+ wids = lexicon.termToWordIds('cats and dogs')
+ self.assertEqual(wids, [1, 2, 3])
+
+ def testBiggerPipelineNofold(self):
+ lexicon = Lexicon(SplitterAdaptor(ZopeSplitter))
+ wids = lexicon.sourceToWordIds('CATS and dogs')
+ wids = lexicon.termToWordIds('cats and dogs')
+ self.assertEqual(wids, [2, 3])
+
def test_suite():
return TestSuite((
makeSuite(Test),
))
+
if __name__=='__main__':
main(defaultTest='test_suite')