[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Indexes/TextIndex/tests - __init__.py:1.1 testBatchedRankedProcessor.py:1.1
Christian Theune
ct@gocept.com
Wed, 4 Dec 2002 05:43:52 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Indexes/TextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv21331/tests
Added Files:
__init__.py testBatchedRankedProcessor.py
Log Message:
- Introducing the query processor for a ranked and batched
TextIndex query.
=== Added File Zope3/lib/python/Zope/App/Indexes/TextIndex/tests/__init__.py ===
# empty __init__.py to make this a package
=== Added File Zope3/lib/python/Zope/App/Indexes/TextIndex/tests/testBatchedRankedProcessor.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
##############################################################################
"""
$Id: testBatchedRankedProcessor.py,v 1.1 2002/12/04 10:43:51 ctheune Exp $
"""
from unittest import TestCase, TestSuite, main, makeSuite
from Zope.App.tests.PlacelessSetup import PlacelessSetup
from Interface.Verify import verifyObject
from Zope.ComponentArchitecture import getAdapter
from Zope.TextIndex.TextIndexInterfaces import IQuerying
from Zope.App.QueryInterfaces.QueryInterfaces import \
IBatchedQuery, ITextIndexQuery, IBatchedResult, \
IRankedHubIdList
from Zope.App.Indexes.TextIndex.BatchedRankedProcessor import \
BatchedRankedProcessor, IBatchedRankedProcessor
from Zope.App.Indexes.TextIndex.TextIndexQueries import \
BatchedRankedResult, BatchedTextIndexQuery
class StupidTextIndex:
__implements__ = IQuerying
def __init__(self, returnvalue):
self.returnvalue = returnvalue
def query(self, querytext, start, count):
"""a stub query processor"""
self.args = (querytext, start, count)
return self.returnvalue
#############################################################################
# If your tests change any global registries, then uncomment the
# following import and include CleanUp as a base class of your
# test. It provides a setUp and tearDown that clear global data that
# has registered with the test cleanup framework. Don't use this
# tests outside the Zope package.
# from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
#############################################################################
class Test(PlacelessSetup, TestCase):
def _Test__new(self):
return BatchedRankedProcessor()
############################################################
# Interface-driven tests:
def test_IVerify(self):
processor = BatchedRankedProcessor(StupidTextIndex(None))
verifyObject(IBatchedRankedProcessor, processor)
def test_parameter(self):
query = BatchedTextIndexQuery(u"test AND foo OR bar", 0, 20)
index = StupidTextIndex(([], 0))
processor = BatchedRankedProcessor(index)
result = processor(query)
# Do introspection for parameterpassing on the index
self.failUnlessEqual(index.args, (u"test AND foo OR bar", 0, 20))
# Do introspection on the result
# BatchedResult
batch = getAdapter(result, IBatchedResult)
self.failUnlessEqual(0, batch.totalSize)
self.failUnlessEqual(0, batch.startPosition)
self.failUnlessEqual(20, batch.batchSize)
# RankedHubIdList
list = getAdapter(result, IRankedHubIdList)
self.failUnlessRaises(IndexError, list.__getitem__, 0)
def test_suite():
return makeSuite(Test)
if __name__=='__main__':
main(defaultTest='test_suite')