[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests - testTextIndexNGinCatalog.py:1.1.2.1

Andreas Jung andreas@digicool.com
Tue, 12 Feb 2002 13:09:42 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests
In directory cvs.zope.org:/tmp/cvs-serv6055

Added Files:
      Tag: ajung-textindexng-branch
	testTextIndexNGinCatalog.py 
Log Message:
same as testTextIndexNG but tests integration of the index into ZCatalog


=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testTextIndexNGinCatalog.py ===
##############################################################################
#
# 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
# 
##############################################################################

import sys, os, unittest

import Zope
from Products.ZCatalog.Catalog import Catalog
from Products.PluginIndexes.TextIndexNG import TextIndexNG
import ExtensionClass

from testTextIndexNG import Tests as testTextIndexNG
from testTextIndexNG import arguments

verbose = 1 
timed_statistics = 0


class TO(ExtensionClass.Base):
    
    def __init__(self,txt,id):
        self.text = txt
        self.id   = id


class Tests(testTextIndexNG):

    def _init(self, arguments):

        index  = TextIndexNG.TextIndexNG(
                            id='text', 
                            extra=arguments,
                            verbose=verbose,
                            timed_statistics=timed_statistics
                        )

        self.catalog = Catalog('catalog')
        self.catalog.addIndex('text', index)
        self.catalog.addColumn('text')
        self.catalog.addColumn('id')

        self.catalog.aq_parent = TO('blabla',-999)

        for id,text in self._testdata:
            obj = TO (text,id)
            self.catalog.catalogObject( obj, str(id) )
        

    def search(self,query, expected):

        res = self.catalog.searchResults({'text':{'query': query}})

        lst = [ r.id    for r in res]
        lst.sort()

        expected_lst = list(expected)
        expected_lst.sort()

        self.assertEqual( lst, expected_lst , \
            'Query: "%s", got: %s, expected: %s' % (query, lst, expected))

        return lst



def test_suite():
   return unittest.makeSuite(Tests)

def main():
   unittest.TextTestRunner().run(test_suite())

def debug():
   test_suite().debug()

def pdebug():
    import pdb
    pdb.run('debug()')
   
if __name__=='__main__':
   if len(sys.argv) > 1:
      globals()[sys.argv[1]]()
   else:
      main()