[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests - testTextIndexNG.py:1.1.2.1
Andreas Jung
andreas@digicool.com
Tue, 5 Feb 2002 15:46:16 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests
In directory cvs.zope.org:/tmp/cvs-serv19647/tests
Added Files:
Tag: ajung-textindexng-branch
testTextIndexNG.py
Log Message:
added
=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testTextIndexNG.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 import TextIndexNG
from Products.PluginIndexes.TextIndexNG import TextIndexCommon
TextIndexCommon._debug = 0
class TO:
def __init__(self,txt,id):
self.text = txt
self.id = id
class arguments:
def __init__(self, *args, **kw):
for k,v in kw.items():
setattr(self,k,v)
class Tests(unittest.TestCase):
_testdata = (
(1,'this text is a simple text'),
(2,'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG')
)
def _init(self, arguments):
self._index = TextIndexNG.TextIndexNG(id='text', extra=arguments)
for id,text in self._testdata:
obj = TO (text,id)
self._index.index_object(id, obj)
def search(self,query, expected):
res = self._index._apply_index({'text':{'query': query}})
lst = list(res[0])
lst.sort()
expected_lst = list(expected)
expected_lst.sort()
self.assertEqual( lst, expected_lst , (query, expected))
return lst
def testCaseFoldingOn(self):
self._init(arguments(
splitterCasefolding = 1
))
self.search('text', [1] )
self.search('simple', [1] )
self.search('quick', [2] )
self.search('brown', [2] )
self.search('QUICK', [2] )
self.search('BROWN', [2] )
def testCaseFoldingOff(self):
self._init(arguments(
splitterCasefolding = 0
))
self.search('text', [1] )
self.search('simple', [1] )
self.search('quick', [] )
self.search('brown', [] )
self.search('QUICK', [2] )
self.search('BROWN', [2] )
def test_suite():
return unittest.makeSuite(Tests,'test')
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()