[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/ Added tests for sortResults

Hanno Schlichting hannosch at hannosch.eu
Sat Dec 25 14:11:52 EST 2010


Log message for revision 119101:
  Added tests for sortResults
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2010-12-25 18:41:16 UTC (rev 119100)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2010-12-25 19:11:52 UTC (rev 119101)
@@ -634,7 +634,6 @@
         # proportion of the time to perform an indexed search.
         # Try to avoid all non-local attribute lookup inside
         # those loops.
-        assert limit is None or limit > 0, 'Limit value must be 1 or greater'
         _intersection = intersection
         _self__getitem__ = self.__getitem__
         index_key_map = sort_index.documentToKeyMap()

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2010-12-25 18:41:16 UTC (rev 119100)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2010-12-25 19:11:52 UTC (rev 119101)
@@ -151,6 +151,7 @@
             self._len=length
         else:
             self._len = len(seq)
+        self.actual_result_count = self._len
         self._marker = object()
         self._data = [self._marker] * self._len
 

Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2010-12-25 18:41:16 UTC (rev 119100)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/tests/test_catalog.py	2010-12-25 19:11:52 UTC (rev 119101)
@@ -19,6 +19,7 @@
 from itertools import chain
 import random
 
+from BTrees.IIBTree import IISet
 import ExtensionClass
 from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
 from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
@@ -285,7 +286,40 @@
         self.assertEquals(result.index('att1'), 2)
 
     # search
-    # sortResults
+
+    def test_sortResults(self):
+        brains = self._catalog({'att1': 'att1'})
+        rs = IISet([b.getRID() for b in brains])
+        si = self._catalog.getIndex('num')
+        result = self._catalog.sortResults(rs, si)
+        self.assertEqual([r.num for r in result], range(100))
+
+    def test_sortResults_reversed(self):
+        brains = self._catalog({'att1': 'att1'})
+        rs = IISet([b.getRID() for b in brains])
+        si = self._catalog.getIndex('num')
+        result = self._catalog.sortResults(rs, si, reverse=True)
+        self.assertEqual([r.num for r in result], list(reversed(range(100))))
+
+    def test_sortResults_limit(self):
+        brains = self._catalog({'att1': 'att1'})
+        rs = IISet([b.getRID() for b in brains])
+        si = self._catalog.getIndex('num')
+        result = self._catalog.sortResults(rs, si, limit=10)
+        self.assertEqual(len(result), 10)
+        self.assertEqual(result.actual_result_count, 100)
+        self.assertEqual([r.num for r in result], range(10))
+
+    def test_sortResults_limit_reversed(self):
+        brains = self._catalog({'att1': 'att1'})
+        rs = IISet([b.getRID() for b in brains])
+        si = self._catalog.getIndex('num')
+        result = self._catalog.sortResults(rs, si, reverse=True, limit=10)
+        self.assertEqual(len(result), 10)
+        self.assertEqual(result.actual_result_count, 100)
+        expected = list(reversed(range(90, 100)))
+        self.assertEqual([r.num for r in result], expected)
+
     # _get_sort_attr
     # _getSortIndex
     # searchResults



More information about the checkins mailing list