[Zope-CVS] CVS: Products/ZCTextIndex/tests - testZCTextIndex.py:1.9

Tim Peters tim.one@comcast.net
Thu, 16 May 2002 01:07:52 -0400


Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv22121/tests

Modified Files:
	testZCTextIndex.py 
Log Message:
Fairly massive rearrangement to allow the Okapi indexer to reuse
testStopWords().  That isn't the real point.  The real point is to
fiddle the scaffolding enough to make it possible to run a white box
test of the Okapi indexer too.  That isn't here yet.


=== Products/ZCTextIndex/tests/testZCTextIndex.py 1.8 => 1.9 ===
         raise AssertionError, "%s != %s" % (scaled1, scaled2)
 
-class IndexTests(testIndex.CosineIndexTest):
+# Subclasses should derive from one of testIndex.{CosineIndexTest,
+# OkapiIndexTest} too.
+
+class ZCIndexTestsBase:
 
     def setUp(self):
         extra = Extra()
@@ -38,7 +41,7 @@
         extra.lexicon_id = 'lexicon'
         caller = LexiconHolder(Lexicon(Splitter(), CaseNormalizer(),
                                StopWordRemover()))
-        self.zc_index = ZCTextIndex('name', extra, caller, CosineIndex)
+        self.zc_index = ZCTextIndex('name', extra, caller, self.IndexFactory)
         self.index = self.zc_index.index
         self.lexicon = self.zc_index.lexicon
 
@@ -54,10 +57,15 @@
                 self.assertEqual(wids, [])
         self.assertEqual(len(self.index._get_undoinfo(1)), 1)
 
+
+class CosineIndexTests(ZCIndexTestsBase, testIndex.CosineIndexTest):
+
+    # A fairly involved test of the ranking calculations based on
+    # an example set of documents in queries in Managing
+    # Gigabytes, pp. 180-188.  This test peeks into many internals of the
+    # cosine index.
+
     def testRanking(self):
-        # A fairly involved test of the ranking calculations based on
-        # an example set of documents in queries in Managing
-        # Gigabytes, pp. 180-188.
         self.words = ["cold", "days", "eat", "hot", "lot", "nine", "old",
                       "pease", "porridge", "pot"]
         self._ranking_index()
@@ -127,6 +135,10 @@
                 self.assert_(0 <= score <= SCALE_FACTOR)
                 eq(d[doc], score)
 
+class OkapiIndexTests(ZCIndexTestsBase, testIndex.OkapiIndexTest):
+    pass
+
+############################################################################
 # Subclasses of QueryTestsBase must set a class variable IndexFactory to
 # the kind of index to be constructed.
 
@@ -173,9 +185,12 @@
 class OkapiQueryTests(QueryTestsBase):
     IndexFactory = OkapiIndex
 
+############################################################################
+
 def test_suite():
     s = unittest.TestSuite()
-    for klass in IndexTests, CosineQueryTests, OkapiQueryTests:
+    for klass in (CosineIndexTests, OkapiIndexTests,
+                  CosineQueryTests, OkapiQueryTests):
         s.addTest(unittest.makeSuite(klass))
     return s