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

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


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

Added Files:
      Tag: TextIndexDS9-branch
	testLexicon.py 
Log Message:
The interfaces for pipeline elements, the lexicon.

An implementation of the ILexicon.

Test cases.


=== Added File Products/ZCTextIndex/tests/testLexicon.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# 
##############################################################################
"""

Revision information:
$Id: testLexicon.py,v 1.1.2.1 2002/05/01 14:56:36 bwarsaw Exp $
"""

from unittest import TestCase, TestSuite, main, makeSuite

from Products.ZCTextIndex.Lexicon import Lexicon
from Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter.ZopeSplitter \
     import ZopeSplitter

##class StupidPipelineElement:
##    def __init__(self, fromword, toword):
##        self.__fromword = fromword
##        self.__toword = toword

##    def __call__(self, seq):
##        seq.replace(self.__fromword, self.__toword)

class Test(TestCase):
    def testSourceToWordIds(self):
        lexicon = Lexicon(ZopeSplitter)
        wids = lexicon.sourceToWordIds('cats and dogs')
        self.assertEqual(wids, [1, 2, 3])

    def testTermToWordIds(self):
        lexicon = Lexicon(ZopeSplitter)
        wids = lexicon.sourceToWordIds('cats and dogs')
        wids = lexicon.termToWordIds('dogs')
        self.assertEqual(wids, [3])

    def testMissingTermToWordIds(self):
        lexicon = Lexicon(ZopeSplitter)
        wids = lexicon.sourceToWordIds('cats and dogs')
        wids = lexicon.termToWordIds('boxes')
        self.assertEqual(wids, [])


def test_suite():
    return TestSuite((
        makeSuite(Test),
        ))

if __name__=='__main__':
    main(defaultTest='test_suite')