[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/ZCatalog/ -
added test to verify the interface
Yvo Schubbe
y.2004_ at wcm-solutions.de
Thu Aug 12 10:09:49 EDT 2004
Log message for revision 27047:
- added test to verify the interface
- synced interface and help file with implementation
Changed:
U Zope/trunk/lib/python/Products/ZCatalog/IZCatalog.py
U Zope/trunk/lib/python/Products/ZCatalog/help/ZCatalog.py
U Zope/trunk/lib/python/Products/ZCatalog/tests/testCatalog.py
-=-
Modified: Zope/trunk/lib/python/Products/ZCatalog/IZCatalog.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCatalog/IZCatalog.py 2004-08-12 13:57:20 UTC (rev 27046)
+++ Zope/trunk/lib/python/Products/ZCatalog/IZCatalog.py 2004-08-12 14:09:49 UTC (rev 27047)
@@ -228,25 +228,25 @@
queries (even across catalogs) and merge and sort the combined results.
"""
- def refreshCatalog(clear=0, REQUEST=None, pghandler=None):
+ def refreshCatalog(clear=0, pghandler=None):
"""Reindex every object we can find, removing the unreachable
- ones from the index.
-
+ ones from the index.
+
clear -- values: 1|0 clear the catalog before reindexing
- REQUEST -- optional REQUEST object
-
- pghandler -- optional Progresshandler as defined in ProgressHandler.py
- (see also README.txt)
+ pghandler -- optional Progresshandler as defined in ProgressHandler.py
+ (see also README.txt)
"""
- def reindexIndex(name, pghandler=None):
+ def reindexIndex(name, REQUEST, pghandler=None):
"""Reindex a single index.
name -- id of index
- pghandler -- optional Progresshandler as defined in ProgressHandler.py
- (see also README.txt)
+ REQUEST -- REQUEST object
+
+ pghandler -- optional Progresshandler as defined in ProgressHandler.py
+ (see also README.txt)
"""
__doc__ = IZCatalog.__doc__ + __doc__
Modified: Zope/trunk/lib/python/Products/ZCatalog/help/ZCatalog.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCatalog/help/ZCatalog.py 2004-08-12 13:57:20 UTC (rev 27046)
+++ Zope/trunk/lib/python/Products/ZCatalog/help/ZCatalog.py 2004-08-12 14:09:49 UTC (rev 27047)
@@ -7,7 +7,7 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
#
##############################################################################
@@ -229,7 +229,23 @@
queries (even across catalogs) and merge and sort the combined results.
"""
- def refreshCatalog():
+ def refreshCatalog(clear=0, pghandler=None):
"""Reindex every object we can find, removing the unreachable
ones from the index.
+
+ clear -- values: 1|0 clear the catalog before reindexing
+
+ pghandler -- optional Progresshandler as defined in ProgressHandler.py
+ (see also README.txt)
"""
+
+ def reindexIndex(name, REQUEST, pghandler=None):
+ """Reindex a single index.
+
+ name -- id of index
+
+ REQUEST -- REQUEST object
+
+ pghandler -- optional Progresshandler as defined in ProgressHandler.py
+ (see also README.txt)
+ """
Modified: Zope/trunk/lib/python/Products/ZCatalog/tests/testCatalog.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCatalog/tests/testCatalog.py 2004-08-12 13:57:20 UTC (rev 27046)
+++ Zope/trunk/lib/python/Products/ZCatalog/tests/testCatalog.py 2004-08-12 14:09:49 UTC (rev 27047)
@@ -1,24 +1,41 @@
-#!/usr/bin/env python, unittest
+##############################################################################
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Unittests for Catalog.
-# Unittests for Catalog
+$Id:$
+"""
-import os
-import random
import unittest
+import Testing
+import Zope
+Zope.startup()
+from Interface.Verify import verifyClass
+
from itertools import chain
+import random
-import ZODB, OFS.Application
+import ExtensionClass
+import OFS.Application
+from Products.ZCatalog import Vocabulary
+from Products.ZCatalog.Catalog import Catalog
+from Products.ZCatalog.Catalog import CatalogError
+from ZODB.DB import DB
from ZODB.DemoStorage import DemoStorage
-from ZODB.DB import DB
-from Products import ZCatalog
-from Products.ZCatalog import ZCatalog,Vocabulary
-from Products.ZCatalog.Catalog import Catalog, CatalogError
-import ExtensionClass
from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex
+from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
+from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from Products.PluginIndexes.TextIndex.TextIndex import TextIndex
-from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
-from Products.PluginIndexes.KeywordIndex.KeywordIndex import KeywordIndex
def createDatabase():
@@ -129,7 +146,8 @@
class TestZCatalog(unittest.TestCase):
def setUp(self):
- self._catalog = ZCatalog.ZCatalog('Catalog')
+ from Products.ZCatalog.ZCatalog import ZCatalog
+ self._catalog = ZCatalog('Catalog')
self._catalog.resolve_path = self._resolve_num
self._catalog.addIndex('title', 'KeywordIndex')
self._catalog.addColumn('title')
@@ -184,6 +202,13 @@
data = self._catalog.getMetadataForUID('0')
self.assertEqual(data['title'], '0')
+ def test_interface(self):
+ from Products.ZCatalog.IZCatalog import IZCatalog
+ from Products.ZCatalog.ZCatalog import ZCatalog
+
+ verifyClass(IZCatalog, ZCatalog)
+
+
class dummy(ExtensionClass.Base):
att1 = 'att1'
att2 = 'att2'
@@ -425,8 +450,8 @@
self._catalog.catalogObject(ob, `9999`)
brain = self._catalog(num=9999)[0]
self.assertEqual(brain.att1, 'foobar')
-
+
class objRS(ExtensionClass.Base):
def __init__(self,num):
@@ -461,7 +486,7 @@
class TestMerge(unittest.TestCase):
# Test merging results from multiple catalogs
-
+
def setUp(self):
vocabulary = Vocabulary.Vocabulary(
'Vocabulary','Vocabulary', globbing=1)
@@ -478,7 +503,7 @@
obj.big = i > 5
cat.catalogObject(obj, str(i))
self.catalogs.append(cat)
-
+
def testNoFilterOrSort(self):
from Products.ZCatalog.Catalog import mergeResults
results = [cat.searchResults(_merge=0) for cat in self.catalogs]
@@ -486,20 +511,20 @@
results, has_sort_keys=False, reverse=False)]
expected = [r.getRID() for r in chain(*results)]
self.assertEqual(sort(merged_rids), sort(expected))
-
+
def testSortedOnly(self):
from Products.ZCatalog.Catalog import mergeResults
- results = [cat.searchResults(sort_on='num', _merge=0)
+ results = [cat.searchResults(sort_on='num', _merge=0)
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected)
-
+
def testSortReverse(self):
from Products.ZCatalog.Catalog import mergeResults
- results = [cat.searchResults(sort_on='num', _merge=0)
+ results = [cat.searchResults(sort_on='num', _merge=0)
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=True)]
@@ -507,38 +532,39 @@
expected.reverse()
expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected)
-
+
def testLimitSort(self):
from Products.ZCatalog.Catalog import mergeResults
- results = [cat.searchResults(sort_on='num', sort_limit=2, _merge=0)
+ results = [cat.searchResults(sort_on='num', sort_limit=2, _merge=0)
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected)
-
+
def testScored(self):
from Products.ZCatalog.Catalog import mergeResults
- results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
+ results = [cat.searchResults(title='4 or 5 or 6', _merge=0)
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results))
expected = [rid for sortkey, (nscore, score, rid), getitem in expected]
self.assertEqual(merged_rids, expected)
-
+
def testSmallIndexSort(self):
# Test that small index sort optimization is not used for merging
from Products.ZCatalog.Catalog import mergeResults
- results = [cat.searchResults(sort_on='big', _merge=0)
+ results = [cat.searchResults(sort_on='big', _merge=0)
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=False)]
expected = sort(chain(*results))
expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected)
-
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite( TestAddDelColumn ) )
More information about the Zope-Checkins
mailing list