[Zope-Checkins] CVS: Zope2 - testCatalog.py:1.1.2.23

Andreas Jung andreas@yetix.digicool.com
Fri, 9 Mar 2001 11:06:13 -0500


Update of /mnt/cvs-repository/Zope2/lib/python/Products/ZCatalog/tests
In directory yetix:/work/Zope2/CatalogUnit/lib/python/Products/ZCatalog/tests

Modified Files:
      Tag: Catalog-Unittest-Branch
	testCatalog.py 
Log Message:
integrated chris unittestCatalog.py



--- Updated File testCatalog.py in package test --
--- testCatalog.py	2001/03/09 15:05:28	1.1.2.22
+++ testCatalog.py	2001/03/09 16:06:10	1.1.2.23
@@ -7,6 +7,9 @@
     Andreas Jung, andreas@digicool.com
     
     $Log$
+    Revision 1.1.2.23  2001/03/09 16:06:10  andreas
+    integrated chris unittestCatalog.py
+
     Revision 1.1.2.22  2001/03/09 15:05:28  andreas
     rewrote testUpdates()
 
@@ -50,15 +53,20 @@
 
 import Zope
 import ZODB, ZODB.FileStorage
-from Products.ZCatalog import Catalog,Vocabulary
+from Products.ZCatalog import Catalog,ZCatalog,Vocabulary
 import Persistence
 import ExtensionClass
 from Testing import dispatcher
 import keywords
 from zLOG import LOG
 
+from SearchIndex.UnIndex import UnIndex
+from SearchIndex.UnTextIndex import UnTextIndex
+from SearchIndex.UnKeywordIndex import UnKeywordIndex
+from SearchIndex.Lexicon import Lexicon
+
 import getopt,whrandom,thread,time,string,mailbox,rfc822
-from Testing.unittest import TestCase, TestSuite, TextTestRunner
+from Testing.unittest import TestCase, TestSuite, TextTestRunner,makeSuite
 
 
 # maximum number of files to read for the test suite
@@ -557,6 +565,193 @@
 
         return cat,msg_ids
 
+################################################################################
+# Stuff of Chris
+################################################################################
+
+
+class CatalogBase:
+    def setUp(self):
+        self._vocabulary = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary',
+                                                 globbing=1)
+        self._catalog = Catalog.Catalog()
+
+    def tearDown(self):
+        self._vocabulary = self._catalog = None
+
+class TestAddDelColumn(CatalogBase, TestCase):
+    def checkAdd(self):
+        self._catalog.addColumn('id')
+        assert self._catalog.schema.has_key('id') == 1, 'add column failed'
+
+    def checkAddBad(self):
+        try:
+            self._catalog.addColumn('_id')
+        except:
+            pass
+        else:
+            raise 'invalid metadata column check failed'
+
+    def checkDel(self):
+        self._catalog.addColumn('id')
+        self._catalog.delColumn('id')
+        assert self._catalog.schema.has_key('id') != 1, 'del column failed'
+
+class TestAddDelIndexes(CatalogBase, TestCase):
+    def checkAddFieldIndex(self):
+        self._catalog.addIndex('id', 'FieldIndex')
+        assert type(self._catalog.indexes['id']) is type(UnIndex('id')),\
+               'add field index failed'
+
+    def checkAddTextIndex(self):
+        self._catalog.addIndex('id', 'TextIndex')
+        i = self._catalog.indexes['id']
+        assert type(i) is type(UnTextIndex('id', None, None, Lexicon())),\
+               'add text index failed'
+
+    def checkAddKeywordIndex(self):
+        self._catalog.addIndex('id', 'KeywordIndex')
+        i = self._catalog.indexes['id']
+        assert type(i) is type(UnKeywordIndex('id')), 'add kw index failed'
+
+    def checkDelFieldIndex(self):
+        self._catalog.addIndex('id', 'FieldIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+        
+    def checkDelTextIndex(self):
+        self._catalog.addIndex('id', 'TextIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+        
+    def checkDelKeywordIndex(self):
+        self._catalog.addIndex('id', 'KeywordIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+
+class TestSimultaneousAddAndRead(CatalogBase, TestCase):
+    def checkMultiThread(self):
+        pass
+
+class TestZCatalogObject(TestCase):
+    def checkInstantiateWithoutVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
+        zc = ZCatalog.ZCatalog('acatalog')
+        assert hasattr(zc, 'Vocabulary')
+        assert zc.getVocabulary().__class__ == v.__class__
+
+    def checkInstantiateWithGlobbingVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
+        zc._setObject('vocab', v)
+        assert zc.getVocabulary() == v
+
+    def checkInstantiateWithNormalVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=0)
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
+        zc._setObject('vocab', v)
+        assert zc.getVocabulary() == v
+
+class TestCatalogObject(TestCase):
+    def setUp(self):
+        self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary',
+                                                 globbing=1)
+        self._catalog = Catalog.Catalog()
+        self._catalog.addIndex('col1', 'FieldIndex')
+        self._catalog.addIndex('col2', 'TextIndex')
+        self._catalog.addIndex('col3', 'KeywordIndex')
+        self._catalog.addColumn('col1') 
+        self._catalog.addColumn('col2')
+        self._catalog.addColumn('col3')
+        
+        self._catalog.addIndex('att1', 'FieldIndex')
+        self._catalog.addIndex('att2', 'TextIndex')
+        self._catalog.addIndex('att3', 'KeywordIndex')
+        self._catalog.addColumn('att1') 
+        self._catalog.addColumn('att2')
+        self._catalog.addColumn('att3')
+
+        self._catalog.addColumn('num')
+        self.upper = 1000
+        class dummy(ExtensionClass.Base):
+            att1 = 'att1'
+            att2 = 'att2'
+            att3 = ['att3']
+            def __init__(self, num):
+                self.num = num
+                
+            def col1(self):
+                return 'col1'
+
+            def col2(self):
+                return 'col2'
+
+            def col3(self):
+                return ['col3']
+        for x in range(0, self.upper):
+            self._catalog.catalogObject(dummy(x), `x`)
+        self._catalog.aq_parent = dummy('foo') # fake out acquisition
+
+    def tearDown(self):
+        self._vocabulary = self._catalog = None
+
+    def checkResultLength(self):
+        upper = self.upper
+        a = self._catalog()
+        assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
+
+    def checkFieldIndexLength(self):
+        a = self._catalog(att1='att1')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+    def checkTextIndexLength(self):
+        a = self._catalog(att2='att2')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+
+    def checkKeywordIndexLength(self):
+        a = self._catalog(att3='att3')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+
+    def checkUncatalogFieldIndex(self):    
+        self.uncatalog()
+        a = self._catalog(att1='att1')
+        assert len(a) == 0, 'len: %s' % (len(a))
+        
+    def checkUncatalogTextIndex(self):
+        self.uncatalog()
+        a = self._catalog(att2='att2')
+        assert len(a) == 0, 'len: %s' % (len(a))
+
+    def checkUncatalogKeywordIndex(self):
+        self.uncatalog()
+        a = self._catalog(att3='att3')
+        assert len(a) == 0, 'len: %s'%(len(a))
+
+    def checkBadUncatalog(self):
+        try:
+            self._catalog.uncatalogObject('asdasdasd')
+        except:
+            assert 1==2, 'uncatalogObject raised exception on bad uid'
+
+    def checkUniqueValuesForLength(self):
+        a = self._catalog.uniqueValuesFor('att1')
+        assert len(a) == 1, 'bad number of unique values %s' % str(a)
+
+    def checkUniqueValuesForContent(self):
+        a = self._catalog.uniqueValuesFor('att1')
+        assert a[0] == 'att1', 'bad content %s' % str(a[0])
+
+    def uncatalog(self):
+        for x in range(0, self.upper):
+            self._catalog.uncatalogObject(`x`)
+
+# environment
+
+
+
+
     
 
 
@@ -564,9 +759,9 @@
 def usage(program):
     print "Usage: "
     print
-    print "initalize the test catalog:   %s -i -f <maximum number files to use> [-d <data directory>] " % program
-    print "to run the basic tests:       %s -b -f <maximum number files to use> [-n <number of threads>]" % program
-    print "to run the advanced tests:    %s -a -f <maximum number files to use> [-n <number of threads>]" % program
+    print "initalize the test catalog:   %s -i -f <maximum number files to use> " % program
+    print "to run the basic tests:       %s -b -f <maximum number files to use> " % program
+    print "to run the advanced tests:    %s -a -f <maximum number files to use> " % program
 
                 
 if __name__ == '__main__':
@@ -575,7 +770,7 @@
 
     mainThreadID = thread.get_ident()
 
-    opts,args = getopt.getopt(sys.argv[1:],"hiabn:f:",['help'])
+    opts,args = getopt.getopt(sys.argv[1:],"hiabn:f:x",['help'])
     opts.sort()
 
     optsLst = map(lambda x: x[0],opts)
@@ -604,6 +799,19 @@
             
     if '-b' in optsLst:
 
+        # Chris' tests
+        s1 = makeSuite(TestAddDelIndexes, 'check')
+        s2 = makeSuite(TestCatalogObject, 'check')
+        s3 = makeSuite(TestAddDelColumn, 'check')
+        s4 = makeSuite(TestZCatalogObject, 'check')
+    
+        testsuite = TestSuite((s1,s2,s3,s4,))
+
+        runner = TextTestRunner()
+        runner.run(testsuite)
+
+        # andreas' tests
+
         basic_tests = [
              testSearches("testFulltextIndex",numThreads=1),
              testSearches("testFulltextIndex",numThreads= 4),
@@ -637,3 +845,8 @@
 
         runner = TextTestRunner()
         runner.run(testsuite1)
+
+    if '-x' in optsLst:
+
+        print "not implemented"
+



--- Updated File testCatalog.py in package Zope2 --
--- testCatalog.py	2001/03/09 15:05:28	1.1.2.22
+++ testCatalog.py	2001/03/09 16:06:10	1.1.2.23
@@ -7,6 +7,9 @@
     Andreas Jung, andreas@digicool.com
     
     $Log$
+    Revision 1.1.2.23  2001/03/09 16:06:10  andreas
+    integrated chris unittestCatalog.py
+
     Revision 1.1.2.22  2001/03/09 15:05:28  andreas
     rewrote testUpdates()
 
@@ -50,15 +53,20 @@
 
 import Zope
 import ZODB, ZODB.FileStorage
-from Products.ZCatalog import Catalog,Vocabulary
+from Products.ZCatalog import Catalog,ZCatalog,Vocabulary
 import Persistence
 import ExtensionClass
 from Testing import dispatcher
 import keywords
 from zLOG import LOG
 
+from SearchIndex.UnIndex import UnIndex
+from SearchIndex.UnTextIndex import UnTextIndex
+from SearchIndex.UnKeywordIndex import UnKeywordIndex
+from SearchIndex.Lexicon import Lexicon
+
 import getopt,whrandom,thread,time,string,mailbox,rfc822
-from Testing.unittest import TestCase, TestSuite, TextTestRunner
+from Testing.unittest import TestCase, TestSuite, TextTestRunner,makeSuite
 
 
 # maximum number of files to read for the test suite
@@ -557,6 +565,193 @@
 
         return cat,msg_ids
 
+################################################################################
+# Stuff of Chris
+################################################################################
+
+
+class CatalogBase:
+    def setUp(self):
+        self._vocabulary = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary',
+                                                 globbing=1)
+        self._catalog = Catalog.Catalog()
+
+    def tearDown(self):
+        self._vocabulary = self._catalog = None
+
+class TestAddDelColumn(CatalogBase, TestCase):
+    def checkAdd(self):
+        self._catalog.addColumn('id')
+        assert self._catalog.schema.has_key('id') == 1, 'add column failed'
+
+    def checkAddBad(self):
+        try:
+            self._catalog.addColumn('_id')
+        except:
+            pass
+        else:
+            raise 'invalid metadata column check failed'
+
+    def checkDel(self):
+        self._catalog.addColumn('id')
+        self._catalog.delColumn('id')
+        assert self._catalog.schema.has_key('id') != 1, 'del column failed'
+
+class TestAddDelIndexes(CatalogBase, TestCase):
+    def checkAddFieldIndex(self):
+        self._catalog.addIndex('id', 'FieldIndex')
+        assert type(self._catalog.indexes['id']) is type(UnIndex('id')),\
+               'add field index failed'
+
+    def checkAddTextIndex(self):
+        self._catalog.addIndex('id', 'TextIndex')
+        i = self._catalog.indexes['id']
+        assert type(i) is type(UnTextIndex('id', None, None, Lexicon())),\
+               'add text index failed'
+
+    def checkAddKeywordIndex(self):
+        self._catalog.addIndex('id', 'KeywordIndex')
+        i = self._catalog.indexes['id']
+        assert type(i) is type(UnKeywordIndex('id')), 'add kw index failed'
+
+    def checkDelFieldIndex(self):
+        self._catalog.addIndex('id', 'FieldIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+        
+    def checkDelTextIndex(self):
+        self._catalog.addIndex('id', 'TextIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+        
+    def checkDelKeywordIndex(self):
+        self._catalog.addIndex('id', 'KeywordIndex')
+        self._catalog.delIndex('id')
+        assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
+
+class TestSimultaneousAddAndRead(CatalogBase, TestCase):
+    def checkMultiThread(self):
+        pass
+
+class TestZCatalogObject(TestCase):
+    def checkInstantiateWithoutVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
+        zc = ZCatalog.ZCatalog('acatalog')
+        assert hasattr(zc, 'Vocabulary')
+        assert zc.getVocabulary().__class__ == v.__class__
+
+    def checkInstantiateWithGlobbingVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
+        zc._setObject('vocab', v)
+        assert zc.getVocabulary() == v
+
+    def checkInstantiateWithNormalVocab(self):
+        v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=0)
+        zc = ZCatalog.ZCatalog('acatalog', vocab_id='vocab')
+        zc._setObject('vocab', v)
+        assert zc.getVocabulary() == v
+
+class TestCatalogObject(TestCase):
+    def setUp(self):
+        self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary',
+                                                 globbing=1)
+        self._catalog = Catalog.Catalog()
+        self._catalog.addIndex('col1', 'FieldIndex')
+        self._catalog.addIndex('col2', 'TextIndex')
+        self._catalog.addIndex('col3', 'KeywordIndex')
+        self._catalog.addColumn('col1') 
+        self._catalog.addColumn('col2')
+        self._catalog.addColumn('col3')
+        
+        self._catalog.addIndex('att1', 'FieldIndex')
+        self._catalog.addIndex('att2', 'TextIndex')
+        self._catalog.addIndex('att3', 'KeywordIndex')
+        self._catalog.addColumn('att1') 
+        self._catalog.addColumn('att2')
+        self._catalog.addColumn('att3')
+
+        self._catalog.addColumn('num')
+        self.upper = 1000
+        class dummy(ExtensionClass.Base):
+            att1 = 'att1'
+            att2 = 'att2'
+            att3 = ['att3']
+            def __init__(self, num):
+                self.num = num
+                
+            def col1(self):
+                return 'col1'
+
+            def col2(self):
+                return 'col2'
+
+            def col3(self):
+                return ['col3']
+        for x in range(0, self.upper):
+            self._catalog.catalogObject(dummy(x), `x`)
+        self._catalog.aq_parent = dummy('foo') # fake out acquisition
+
+    def tearDown(self):
+        self._vocabulary = self._catalog = None
+
+    def checkResultLength(self):
+        upper = self.upper
+        a = self._catalog()
+        assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
+
+    def checkFieldIndexLength(self):
+        a = self._catalog(att1='att1')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+    def checkTextIndexLength(self):
+        a = self._catalog(att2='att2')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+
+    def checkKeywordIndexLength(self):
+        a = self._catalog(att3='att3')
+        assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
+                                                                  len(a))
+
+    def checkUncatalogFieldIndex(self):    
+        self.uncatalog()
+        a = self._catalog(att1='att1')
+        assert len(a) == 0, 'len: %s' % (len(a))
+        
+    def checkUncatalogTextIndex(self):
+        self.uncatalog()
+        a = self._catalog(att2='att2')
+        assert len(a) == 0, 'len: %s' % (len(a))
+
+    def checkUncatalogKeywordIndex(self):
+        self.uncatalog()
+        a = self._catalog(att3='att3')
+        assert len(a) == 0, 'len: %s'%(len(a))
+
+    def checkBadUncatalog(self):
+        try:
+            self._catalog.uncatalogObject('asdasdasd')
+        except:
+            assert 1==2, 'uncatalogObject raised exception on bad uid'
+
+    def checkUniqueValuesForLength(self):
+        a = self._catalog.uniqueValuesFor('att1')
+        assert len(a) == 1, 'bad number of unique values %s' % str(a)
+
+    def checkUniqueValuesForContent(self):
+        a = self._catalog.uniqueValuesFor('att1')
+        assert a[0] == 'att1', 'bad content %s' % str(a[0])
+
+    def uncatalog(self):
+        for x in range(0, self.upper):
+            self._catalog.uncatalogObject(`x`)
+
+# environment
+
+
+
+
     
 
 
@@ -564,9 +759,9 @@
 def usage(program):
     print "Usage: "
     print
-    print "initalize the test catalog:   %s -i -f <maximum number files to use> [-d <data directory>] " % program
-    print "to run the basic tests:       %s -b -f <maximum number files to use> [-n <number of threads>]" % program
-    print "to run the advanced tests:    %s -a -f <maximum number files to use> [-n <number of threads>]" % program
+    print "initalize the test catalog:   %s -i -f <maximum number files to use> " % program
+    print "to run the basic tests:       %s -b -f <maximum number files to use> " % program
+    print "to run the advanced tests:    %s -a -f <maximum number files to use> " % program
 
                 
 if __name__ == '__main__':
@@ -575,7 +770,7 @@
 
     mainThreadID = thread.get_ident()
 
-    opts,args = getopt.getopt(sys.argv[1:],"hiabn:f:",['help'])
+    opts,args = getopt.getopt(sys.argv[1:],"hiabn:f:x",['help'])
     opts.sort()
 
     optsLst = map(lambda x: x[0],opts)
@@ -604,6 +799,19 @@
             
     if '-b' in optsLst:
 
+        # Chris' tests
+        s1 = makeSuite(TestAddDelIndexes, 'check')
+        s2 = makeSuite(TestCatalogObject, 'check')
+        s3 = makeSuite(TestAddDelColumn, 'check')
+        s4 = makeSuite(TestZCatalogObject, 'check')
+    
+        testsuite = TestSuite((s1,s2,s3,s4,))
+
+        runner = TextTestRunner()
+        runner.run(testsuite)
+
+        # andreas' tests
+
         basic_tests = [
              testSearches("testFulltextIndex",numThreads=1),
              testSearches("testFulltextIndex",numThreads= 4),
@@ -637,3 +845,8 @@
 
         runner = TextTestRunner()
         runner.run(testsuite1)
+
+    if '-x' in optsLst:
+
+        print "not implemented"
+