[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/tests - testCatalog.py:1.18.2.1
Casey Duncan
casey@zope.com
Tue, 10 Dec 2002 10:55:01 -0500
Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/tests
In directory cvs.zope.org:/tmp/cvs-serv31233/lib/python/Products/ZCatalog/tests
Modified Files:
Tag: Zope-2_6-branch
testCatalog.py
Log Message:
Backport catalog sort speedups from the HEAD sans ZCatalog and PlugInIndex API changes
=== Zope/lib/python/Products/ZCatalog/tests/testCatalog.py 1.18 => 1.18.2.1 ===
--- Zope/lib/python/Products/ZCatalog/tests/testCatalog.py:1.18 Wed Aug 28 13:08:50 2002
+++ Zope/lib/python/Products/ZCatalog/tests/testCatalog.py Tue Dec 10 10:55:00 2002
@@ -17,7 +17,7 @@
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
-import whrandom,string, unittest
+import whrandom,string, unittest, random
def createDatabase():
@@ -157,8 +157,23 @@
testNum = str(self.upper - 3)
data = self._catalog.getIndexDataForUID(testNum)
assert data['title'][0] == testNum
+
+ def testSearch(self):
+ query = {'title': ['5','6','7']}
+ sr = self._catalog.searchResults(query)
+ self.assertEqual(len(sr), 3)
class TestCatalogObject(unittest.TestCase):
+
+ upper = 1000
+
+ nums = range(upper)
+ for i in range(upper):
+ j = random.randint(0, upper-1)
+ tmp = nums[i]
+ nums[i] = nums[j]
+ nums[j] = tmp
+
def setUp(self):
self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary',
globbing=1)
@@ -189,7 +204,6 @@
self._catalog.addColumn('att3')
self._catalog.addColumn('num')
- self.upper = 1000
class dummy(ExtensionClass.Base):
att1 = 'att1'
att2 = 'att2'
@@ -206,9 +220,9 @@
def col3(self):
return ['col3']
-
+
for x in range(0, self.upper):
- self._catalog.catalogObject(dummy(x), `x`)
+ self._catalog.catalogObject(dummy(self.nums[x]), `x`)
self._catalog.aq_parent = dummy('foo') # fake out acquisition
def tearDown(self):
@@ -346,6 +360,33 @@
# set is much larger than the sort index.
a = self._catalog(sort_on='att1')
self.assertEqual(len(a), self.upper)
+
+ def testBadSortLimits(self):
+ self.assertRaises(
+ AssertionError, self._catalog, sort_on='num', sort_limit=0)
+ self.assertRaises(
+ AssertionError, self._catalog, sort_on='num', sort_limit=-10)
+
+ def testSortLimit(self):
+ full = self._catalog(sort_on='num')
+ a = self._catalog(sort_on='num', sort_limit=10)
+ self.assertEqual([r.num for r in a], [r.num for r in full[:10]])
+ self.assertEqual(a.actual_result_count, self.upper)
+ a = self._catalog(sort_on='num', sort_limit=10, sort_order='reverse')
+ rev = [r.num for r in full[-10:]]
+ rev.reverse()
+ self.assertEqual([r.num for r in a], rev)
+ self.assertEqual(a.actual_result_count, self.upper)
+
+ def testBigSortLimit(self):
+ a = self._catalog(sort_on='num', sort_limit=self.upper*3)
+ self.assertEqual(a.actual_result_count, self.upper)
+ self.assertEqual(a[0].num, 0)
+ a = self._catalog(
+ sort_on='num', sort_limit=self.upper*3, sort_order='reverse')
+ self.assertEqual(a.actual_result_count, self.upper)
+ self.assertEqual(a[0].num, self.upper - 1)
+
class objRS(ExtensionClass.Base):