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

Andreas Jung andreas@digicool.com
Wed, 9 Jan 2002 15:21:29 -0500


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

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


=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testGlobbingLexiconNG.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.GlobbingLexiconNG \
        import GlobbingLexiconNG

from testLexiconNG import Tests as LexiconTestBase


class Tests(LexiconTestBase):

    def setUp(self):
        self._lexicon  = GlobbingLexiconNG()    


    def _cmp(self,a,b):

        L = self._lexicon

        l1 = list(L.get(a))
        l1.sort()

        l2 = list(L.get(b))
        l2.sort()

        print l1,l2
        return l1,l2

        
    def testSimpleGlobbing(self):
        """ test simple globbing functionality """

        L = self._lexicon

        s = "the quick brown fox jumps over the lazy dog"
        words = s.split()

        wids = {}
        for word in words:
            wids[word] = L.getWordId(word)

        c = self._cmp

        apply(self.assertEqual, c('the', 't*'))
        apply(self.assertEqual, c('the', 'th*'))
        apply(self.assertEqual, c('the', 'the*'))
       
        apply(self.assertEqual, c('brown', 'b*'))
        apply(self.assertEqual, c('brown', 'br*'))
        apply(self.assertEqual, c('brown', 'bro*'))
        apply(self.assertEqual, c('brown', 'brow*'))
        apply(self.assertEqual, c('brown', 'brown*'))


    def testLatin1Globbing(self):
        """ test simple globbing functionality """

        L = self._lexicon

        s = 'Bei den dreitägigen Angriffen seien auch bis'
        words = s.split()

        wids = {}
        for word in words:
            wids[word] = L.getWordId(word)

        c = self._cmp

        apply(self.assertEqual, c('seien', 's*'))
        apply(self.assertEqual, c('seien', 'sei*'))
        apply(self.assertEqual, c('seien', 'seie*'))
        apply(self.assertEqual, c('seien', 'seien*'))

        self.printLexicon()       
        apply(self.assertEqual, c('dreitägigen', 'drei*'))
        apply(self.assertEqual, c('dreitägigen', 'dreit*'))
        apply(self.assertEqual, c('dreitägigen', 'dreitä*'))
        apply(self.assertEqual, c('dreitägigen', 'dreitägig*'))


    def testUnicodeGlobbing(self):
        """ test simple globbing functionality """

        L = self._lexicon

        s = unicode('Bei den dreitägigen Angriffen seien auch bis','latin1')
        words = s.split()

        wids = {}
        for word in words:
            wids[word] = L.getWordId(word)

        c = self._cmp

        apply(self.assertEqual, c('seien', 's*'))
        apply(self.assertEqual, c('seien', 'sei*'))
        apply(self.assertEqual, c('seien', 'seie*'))
        apply(self.assertEqual, c('seien', 'seien*'))

        self.printLexicon()       
        apply(self.assertEqual, c('dreitägigen', 'drei*'))
        apply(self.assertEqual, c('dreitägigen', 'dreit*'))
        apply(self.assertEqual, c('dreitägigen', 'dreitä*'))
        apply(self.assertEqual, c('dreitägigen', 'dreitägig*'))


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()



=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testLexiconNG.py 1.1.2.1 => 1.1.2.2 ===
     def setUp(self):
         self._lexicon  = LexiconNG()    
-        self._string   = 'the quick brown fox jumps over the lazy dog'
 
     def doTest(self,s):
         """ simple tests """
@@ -60,6 +59,11 @@
                  'latin1')
 
         self.doTest(s)
+
+    def printLexicon(self):
+
+        for k,v in self._lexicon._lexicon.items():
+            print k.encode('latin1'),v