[Zope-CVS] CVS: Products/ZCTextIndex/tests - testZCTextIndex.py:1.8
Tim Peters
tim.one@comcast.net
Thu, 16 May 2002 00:46:12 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv15364/tests
Modified Files:
testZCTextIndex.py
Log Message:
Run the Query tests on the Okapi indexer as well as the cosine indexer.
=== Products/ZCTextIndex/tests/testZCTextIndex.py 1.7 => 1.8 ===
from Products.ZCTextIndex.tests \
import testIndex, testQueryEngine, testQueryParser
-from Products.ZCTextIndex.Index import scaled_int, SCALE_FACTOR, Index
+from Products.ZCTextIndex.Index import scaled_int, SCALE_FACTOR
+from Products.ZCTextIndex.Index import Index as CosineIndex
+from Products.ZCTextIndex.OkapiIndex import Index as OkapiIndex
from Products.ZCTextIndex.Lexicon import Lexicon, Splitter
from Products.ZCTextIndex.Lexicon import CaseNormalizer, StopWordRemover
from Products.ZCTextIndex.QueryParser import QueryParser
@@ -36,7 +38,7 @@
extra.lexicon_id = 'lexicon'
caller = LexiconHolder(Lexicon(Splitter(), CaseNormalizer(),
StopWordRemover()))
- self.zc_index = ZCTextIndex('name', extra, caller, Index)
+ self.zc_index = ZCTextIndex('name', extra, caller, CosineIndex)
self.index = self.zc_index.index
self.lexicon = self.zc_index.lexicon
@@ -125,8 +127,11 @@
self.assert_(0 <= score <= SCALE_FACTOR)
eq(d[doc], score)
-class QueryTests(testQueryEngine.TestQueryEngine,
- testQueryParser.TestQueryParser):
+# Subclasses of QueryTestsBase must set a class variable IndexFactory to
+# the kind of index to be constructed.
+
+class QueryTestsBase(testQueryEngine.TestQueryEngine,
+ testQueryParser.TestQueryParser):
# The FauxIndex in testQueryEngine contains four documents.
# docid 1: foo, bar, ham
@@ -142,7 +147,7 @@
extra.lexicon_id = 'lexicon'
caller = LexiconHolder(Lexicon(Splitter(), CaseNormalizer(),
StopWordRemover()))
- self.zc_index = ZCTextIndex('name', extra, caller)
+ self.zc_index = ZCTextIndex('name', extra, caller, self.IndexFactory)
self.p = self.parser = QueryParser()
self.index = self.zc_index.index
self.add_docs()
@@ -162,10 +167,15 @@
d[k] = v
self.assertEqual(d.keys(), dict.keys())
+class CosineQueryTests(QueryTestsBase):
+ IndexFactory = CosineIndex
+
+class OkapiQueryTests(QueryTestsBase):
+ IndexFactory = OkapiIndex
def test_suite():
s = unittest.TestSuite()
- for klass in IndexTests, QueryTests:
+ for klass in IndexTests, CosineQueryTests, OkapiQueryTests:
s.addTest(unittest.makeSuite(klass))
return s