[Checkins] SVN: Zope/branches/2.12/src/Products/ZCTextIndex/ Flesh out tests for PLexicon.queryLexicon.

Tres Seaver tseaver at palladion.com
Mon Apr 12 08:26:37 EDT 2010


Log message for revision 110738:
  Flesh out tests for PLexicon.queryLexicon.

Changed:
  U   Zope/branches/2.12/src/Products/ZCTextIndex/ZCTextIndex.py
  U   Zope/branches/2.12/src/Products/ZCTextIndex/tests/testZCTextIndex.py

-=-
Modified: Zope/branches/2.12/src/Products/ZCTextIndex/ZCTextIndex.py
===================================================================
--- Zope/branches/2.12/src/Products/ZCTextIndex/ZCTextIndex.py	2010-04-12 11:35:51 UTC (rev 110737)
+++ Zope/branches/2.12/src/Products/ZCTextIndex/ZCTextIndex.py	2010-04-12 12:26:37 UTC (rev 110738)
@@ -384,16 +384,27 @@
             columns.append(words[i:i + rows])
             i += rows
 
-        return self._queryLexicon(self, REQUEST,
-                                  page=page,
-                                  rows=rows,
-                                  cols=cols,
-                                  start_word=start+1,
-                                  end_word=end,
-                                  word_count=word_count,
-                                  page_count=page_count,
-                                  page_range=xrange(page_count),
-                                  page_columns=columns)
+        if REQUEST is not None:
+            return self._queryLexicon(self,
+                                      REQUEST,
+                                      page=page,
+                                      rows=rows,
+                                      cols=cols,
+                                      start_word=start+1,
+                                      end_word=end,
+                                      word_count=word_count,
+                                      page_count=page_count,
+                                      page_range=xrange(page_count),
+                                      page_columns=columns)
+        return dict(page=page,
+                    rows=rows,
+                    cols=cols,
+                    start_word=start+1,
+                    end_word=end,
+                    word_count=word_count,
+                    page_count=page_count,
+                    page_range=xrange(page_count),
+                    page_columns=columns)
 
     security.declareProtected(LexiconMgmtPerm, 'manage_main')
     manage_main = DTMLFile('dtml/manageLexicon', globals())

Modified: Zope/branches/2.12/src/Products/ZCTextIndex/tests/testZCTextIndex.py
===================================================================
--- Zope/branches/2.12/src/Products/ZCTextIndex/tests/testZCTextIndex.py	2010-04-12 11:35:51 UTC (rev 110737)
+++ Zope/branches/2.12/src/Products/ZCTextIndex/tests/testZCTextIndex.py	2010-04-12 12:26:37 UTC (rev 110738)
@@ -245,6 +245,7 @@
                     nbest, total = self.zc_index.query(w)
                     self.assertEqual(total, 0, "did not expect to find %s" % w)
 
+
 class CosineIndexTests(ZCIndexTestsBase, testIndex.CosineIndexTest):
 
     # A fairly involved test of the ranking calculations based on
@@ -566,15 +567,46 @@
 
 class PLexiconTests(unittest.TestCase):
 
-    def test_z3interfaces(self):
+    def _getTargetClass(self):
+        from Products.ZCTextIndex.ZCTextIndex import PLexicon
+        return PLexicon
+
+    def _makeOne(self, id='testing', title='Testing', *pipeline):
+        return self._getTargetClass()(id, title, *pipeline)
+
+    def test_class_conforms_to_ILexicon(self):
         from Products.ZCTextIndex.interfaces import ILexicon
+        from zope.interface.verify import verifyClass
+        verifyClass(ILexicon, self._getTargetClass())
+
+    def test_instance_conforms_to_ILexicon(self):
+        from Products.ZCTextIndex.interfaces import ILexicon
+        from zope.interface.verify import verifyObject
+        verifyObject(ILexicon, self._makeOne())
+
+    def test_class_conforms_to_IZCLexicon(self):
         from Products.ZCTextIndex.interfaces import IZCLexicon
         from zope.interface.verify import verifyClass
+        verifyClass(IZCLexicon, self._getTargetClass())
 
-        verifyClass(ILexicon, PLexicon)
-        verifyClass(IZCLexicon, PLexicon)
+    def test_instance_conforms_to_IZCLexicon(self):
+        from Products.ZCTextIndex.interfaces import IZCLexicon
+        from zope.interface.verify import verifyObject
+        verifyObject(IZCLexicon, self._makeOne())
 
+    def test_queryLexicon_defaults(self):
+        index = self._makeOne()
+        info = index.queryLexicon(REQUEST=None, words=None)
+        self.assertEqual(info['page'], 0)
+        self.assertEqual(info['rows'], 20)
+        self.assertEqual(info['cols'], 4)
+        self.assertEqual(info['start_word'], 1)
+        self.assertEqual(info['end_word'], 0)
+        self.assertEqual(info['word_count'], 0)
+        self.assertEqual(list(info['page_range']), [])
+        self.assertEqual(info['page_columns'], [])
 
+
 def test_suite():
     s = unittest.TestSuite()
     for klass in (CosineIndexTests, OkapiIndexTests,



More information about the checkins mailing list