[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests - testLexiconNG.py:1.1.2.1

Andreas Jung andreas@digicool.com
Wed, 9 Jan 2002 14:45:53 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests
In directory cvs.zope.org:/tmp/cvs-serv19774

Added Files:
      Tag: ajung-textindexng-branch
	testLexiconNG.py 
Log Message:
added


=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testLexiconNG.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################

import sys, os, unittest

from Products.PluginIndexes.TextIndexNG.LexiconNG import LexiconNG


class Tests(unittest.TestCase):

    def setUp(self):
        self._lexicon  = LexiconNG()    
        self._string   = 'the quick brown fox jumps over the lazy dog'

    def doTest(self,s):
        """ simple tests """

        words = s.split()

        self.assertEqual(len(self._lexicon),0)
        
        wids = {}
        for w in words:
            wids[w] = self._lexicon.getWordId(w)

        self.assertEqual(len(self._lexicon),len(wids))

        for w in words:
            wids[w] = self._lexicon.getWordId(w)
        self.assertEqual(len(self._lexicon),len(wids))


        for word,wid in wids.items():
            self.assertEqual(self._lexicon.getWord(wid), word)
            self.assertEqual(self._lexicon.getWordId(word), wid)


    def testSimple(self):
        """ a simple test """

        s = 'the quick brown fox jumps over the lazy dog'
        self.doTest(s)


    def testUnicode(self):
        """ a simple test """

        s = unicode( 'Bei den dreitägigen Angriffen seien auch bis'
                 ' auf einen alle Flugplätze der Taliban zerstört worden',
                 'latin1')

        self.doTest(s)
        
       

def test_suite():
   return unittest.makeSuite(Tests)

def main():
   unittest.TextTestRunner().run(test_suite())

def debug():
   test_suite().debug()

def pdebug():
    import pdb
    pdb.run('debug()')
   
if __name__=='__main__':
   if len(sys.argv) > 1:
      globals()[sys.argv[1]]()
   else:
      main()