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

Jeremy Hylton jeremy@zope.com
Thu, 2 May 2002 12:19:25 -0400


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

Modified Files:
      Tag: TextIndexDS9-branch
	testZCTextIndex.py 
Log Message:
Add query tests to ZCTextIndex tests.


=== Products/ZCTextIndex/tests/testZCTextIndex.py 1.1.2.1 => 1.1.2.2 ===
-from Products.ZCTextIndex.tests import testIndex
+from Products.ZCTextIndex.tests \
+     import testIndex, testQueryEngine, testQueryParser
 
 import unittest
 
-class ZCTextIndexTests(testIndex.IndexTest):
+# The tests classes below create a ZCTextIndex().  Then they create
+# instance variables that point to the internal components used by
+# ZCTextIndex.  These tests run the individual module unit tests with
+# the fully integrated ZCTextIndex.
+
+class IndexTests(testIndex.IndexTest):
 
     def setUp(self):
         self.zc_index = ZCTextIndex()
-        # setup the attrs that the testIndex tests expect
         self.index = self.zc_index.index
         self.lexicon = self.zc_index.lexicon
 
+class QueryTests(testQueryEngine.TestQueryEngine,
+                 testQueryParser.TestQueryParser):
+
+    # The FauxIndex in testQueryEngine contains four documents.
+    # docid 1: foo, bar, ham
+    # docid 2: bar, ham
+    # docid 3: foo, ham
+    # docid 4: ham
+
+    docs = ["foo bar ham", "bar ham", "foo ham", "ham"]
+
+    def setUp(self):
+        self.zc_index = ZCTextIndex()
+        self.p = self.parser = self.zc_index.parser
+        self.engine = self.zc_index.engine
+        self.index = self.zc_index.index
+        self.add_docs()
+
+    def add_docs(self):
+        for i in range(len(self.docs)):
+            text = self.docs[i]
+            obj = testIndex.Indexable(text)
+            self.zc_index.index_object(i + 1, obj)
+
+    def compareSet(self, set, dict):
+        # XXX The FauxIndex and the real Index score documents very
+        # differently.  The set comparison can't actually compare the
+        # items, but it can compare the keys.  That will have to do for now.
+        d = {}
+        for k, v in set.items():
+            d[k] = v
+        self.assertEqual(d.keys(), dict.keys())
+        
+
 def test_suite():
-    return unittest.makeSuite(ZCTextIndexTests)
+    s = unittest.TestSuite()
+    for klass in IndexTests, QueryTests:
+        s.addTest(unittest.makeSuite(klass))
+    return s
 
 if __name__=='__main__':
     unittest.main(defaultTest='test_suite')