[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog/tests - framework.py:1.1 testCatalog.py:1.8

Andreas Jung andreas@zope.com
Tue, 9 Oct 2001 13:56:05 -0400


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog/tests
In directory cvs.zope.org:/tmp/cvs-serv25011

Modified Files:
	testCatalog.py 
Added Files:
	framework.py 
Log Message:
- some internal work to add support for framework.py


=== Added File Zope/lib/python/Products/ZCatalog/tests/framework.py ===
##############################################################################
# 
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
# 
# Copyright (c) Digital Creations.  All rights reserved.
# 
# This license has been certified as Open Source(tm).
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 
# 1. Redistributions in source code must retain the above copyright
#    notice, this list of conditions, and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions, and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 
# 3. Digital Creations requests that attribution be given to Zope
#    in any manner possible. Zope includes a "Powered by Zope"
#    button that is installed by default. While it is not a license
#    violation to remove this button, it is requested that the
#    attribution remain. A significant investment has been put
#    into Zope, and this effort will continue if the Zope community
#    continues to grow. This is one way to assure that growth.
# 
# 4. All advertising materials and documentation mentioning
#    features derived from or use of this software must display
#    the following acknowledgement:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    In the event that the product being advertised includes an
#    intact Zope distribution (with copyright and license included)
#    then this clause is waived.
# 
# 5. Names associated with Zope or Digital Creations must not be used to
#    endorse or promote products derived from this software without
#    prior written permission from Digital Creations.
# 
# 6. Modified redistributions of any form whatsoever must retain
#    the following acknowledgment:
# 
#      "This product includes software developed by Digital Creations
#      for use in the Z Object Publishing Environment
#      (http://www.zope.org/)."
# 
#    Intact (re-)distributions of any official Zope release do not
#    require an external acknowledgement.
# 
# 7. Modifications are encouraged but must be packaged separately as
#    patches to official Zope releases.  Distributions that do not
#    clearly separate the patches from the original work must be clearly
#    labeled as unofficial distributions.  Modifications which do not
#    carry the name Zope may be packaged in any form, as long as they
#    conform to all of the clauses above.
# 
# 
# Disclaimer
# 
#   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
#   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
#   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
#   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
#   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#   SUCH DAMAGE.
# 
# 
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations.  Specific
# attributions are listed in the accompanying credits file.
# 
##############################################################################

######################################################################
# Set up unit testing framework
#
# The following code should be at the top of every test module:
#
# import os, sys
# execfile(os.path.join(sys.path[0], 'framework.py'))
#
# ...and the following at the bottom:
#
# framework()


# Find the Testing package
if not sys.modules.has_key('Testing'):
    p0 = sys.path[0]
    if p0 and __name__ == '__main__':
        os.chdir(p0)
        p0 = ''
    p = d = os.path.abspath(os.curdir)
    while d:
        if os.path.isdir(os.path.join(p, 'Testing')):
            sys.path[:1] = [p0, os.pardir, p]
            break
        p, d = os.path.split(p)
    else:
        print 'Unable to locate Testing package.'
        sys.exit(1)

import Testing, unittest
execfile(os.path.join(os.path.split(Testing.__file__)[0], 'common.py'))




=== Zope/lib/python/Products/ZCatalog/tests/testCatalog.py 1.7 => 1.8 ===
 # Unittests for Catalog
 
-
 import os,sys
-sys.path.insert(0,'.')
-
+execfile(os.path.join(sys.path[0],'framework.py'))
 os.environ['STUPID_LOG_FILE']= "debug.log"
 
 import Zope
@@ -36,12 +34,12 @@
     def tearDown(self):
         self._vocabulary = self._catalog = None
 
-class TestAddDelColumn(CatalogBase, unittest.TestCase):
-    def checkAdd(self):
+class TestAddDelColumn(unittest.TestCase,CatalogBase):
+    def testAdd(self):
         self._catalog.addColumn('id')
         assert self._catalog.schema.has_key('id') == 1, 'add column failed'
 
-    def checkAddBad(self):
+    def testAddBad(self):
         try:
             self._catalog.addColumn('_id')
         except:
@@ -49,44 +47,44 @@
         else:
             raise 'invalid metadata column check failed'
 
-    def checkDel(self):
+    def testDel(self):
         self._catalog.addColumn('id')
         self._catalog.delColumn('id')
         assert self._catalog.schema.has_key('id') != 1, 'del column failed'
 
 class TestAddDelIndexes(CatalogBase, unittest.TestCase):
-    def checkAddFieldIndex(self):
+    def testAddFieldIndex(self):
         idx = FieldIndex('id')
         self._catalog.addIndex('id', idx)
         assert type(self._catalog.indexes['id']) is type(FieldIndex('id')),\
                'add field index failed'
 
-    def checkAddTextIndex(self):
+    def testAddTextIndex(self):
         idx = TextIndex('id')
         self._catalog.addIndex('id', idx)
         i = self._catalog.indexes['id']
         assert type(i) is type(TextIndex('id', None, None, Lexicon())),\
                'add text index failed'
 
-    def checkAddKeywordIndex(self):
+    def testAddKeywordIndex(self):
         idx = KeywordIndex('id')
         self._catalog.addIndex('id', idx)
         i = self._catalog.indexes['id']
         assert type(i) is type(KeywordIndex('id')), 'add kw index failed'
 
-    def checkDelFieldIndex(self):
+    def testDelFieldIndex(self):
         idx = FieldIndex('id')
         self._catalog.addIndex('id', idx)
         self._catalog.delIndex('id')
         assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
         
-    def checkDelTextIndex(self):
+    def testDelTextIndex(self):
         idx = TextIndex('id')
         self._catalog.addIndex('id', idx)
         self._catalog.delIndex('id')
         assert self._catalog.indexes.has_key('id') != 1, 'del index failed'
         
-    def checkDelKeywordIndex(self):
+    def testDelKeywordIndex(self):
         idx = KeywordIndex('id')
         self._catalog.addIndex('id', idx)
         self._catalog.delIndex('id')
@@ -101,13 +99,13 @@
     def tearDown(self):
         self.dummy = None
 
-    def checkInstantiateWithoutVocab(self):
+    def testInstantiateWithoutVocab(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):
+    def testInstantiateWithGlobbingVocab(self):
         dummy = self.dummy
         v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=1)
         dummy.v = v
@@ -115,7 +113,7 @@
         zc = zc.__of__(dummy)
         assert zc.getVocabulary() == v
 
-    def checkInstantiateWithNormalVocab(self):
+    def testInstantiateWithNormalVocab(self):
         dummy = self.dummy
         v = Vocabulary.Vocabulary('Vocabulary', 'Vocabulary', globbing=0)
         dummy.v = v
@@ -179,64 +177,64 @@
     def tearDown(self):
         self._vocabulary = self._catalog = None
 
-    def checkResultLength(self):
+    def testResultLength(self):
         upper = self.upper
         a = self._catalog()
         assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
 
-    def checkEmptyMappingReturnsAll(self):
+    def testEmptyMappingReturnsAll(self):
         upper = self.upper
         a = self._catalog({})
         assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
 
-    def checkFieldIndexLength(self):
+    def testFieldIndexLength(self):
         a = self._catalog(att1='att1')
         assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
                                                                   len(a))
-    def checkTextIndexLength(self):
+    def testTextIndexLength(self):
         a = self._catalog(att2='att2')
         assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
                                                                   len(a))
 
-    def checkKeywordIndexLength(self):
+    def testKeywordIndexLength(self):
         a = self._catalog(att3='att3')
         assert len(a) == self.upper, 'should be %s, but is %s' % (self.upper,
                                                                   len(a))
 
-    def checkUncatalogFieldIndex(self):    
+    def testUncatalogFieldIndex(self):    
         self.uncatalog()
         a = self._catalog(att1='att1')
         assert len(a) == 0, 'len: %s' % (len(a))
         
-    def checkUncatalogTextIndex(self):
+    def testUncatalogTextIndex(self):
         self.uncatalog()
         a = self._catalog(att2='att2')
         assert len(a) == 0, 'len: %s' % (len(a))
 
-    def checkUncatalogKeywordIndex(self):
+    def testUncatalogKeywordIndex(self):
         self.uncatalog()
         a = self._catalog(att3='att3')
         assert len(a) == 0, 'len: %s'%(len(a))
 
-    def checkBadUncatalog(self):
+    def testBadUncatalog(self):
         try:
             self._catalog.uncatalogObject('asdasdasd')
         except:
             assert 1==2, 'uncatalogObject raised exception on bad uid'
 
-    def checkUniqueValuesForLength(self):
+    def testUniqueValuesForLength(self):
         a = self._catalog.uniqueValuesFor('att1')
         assert len(a) == 1, 'bad number of unique values %s' % str(a)
 
-    def checkUniqueValuesForContent(self):
+    def testUniqueValuesForContent(self):
         a = self._catalog.uniqueValuesFor('att1')
         assert a[0] == 'att1', 'bad content %s' % str(a[0])
 
-    def checkUncatalogTwice(self):
+    def testUncatalogTwice(self):
         self._catalog.uncatalogObject(`0`)
         self.assertRaises(Exception, '_second')
 
-    def checkCatalogLength(self):
+    def testCatalogLength(self):
         for x in range(0, self.upper):
             self._catalog.uncatalogObject(`x`)
         assert len(self._catalog) == 0
@@ -248,52 +246,52 @@
         for x in range(0, self.upper):
             self._catalog.uncatalogObject(`x`)
 
-    def checkGoodSortIndex(self):
+    def testGoodSortIndex(self):
         upper = self.upper
         a = self._catalog(sort_on='num')
         assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
         for x in range(self.upper):
             assert a[x].num == x, x
             
-    def checkBadSortIndex(self):
+    def testBadSortIndex(self):
         self.assertRaises(CatalogError, self.badsortindex)
 
     def badsortindex(self):
         a = self._catalog(sort_on='foofaraw')
 
-    def checkWrongKindOfIndexForSort(self):
+    def testWrongKindOfIndexForSort(self):
         self.assertRaises(CatalogError, self.wrongsortindex)
 
     def wrongsortindex(self):
         a = self._catalog(sort_on='att2')
 
-    def checkTextIndexQWithSortOn(self):
+    def testTextIndexQWithSortOn(self):
         upper = self.upper
         a = self._catalog(sort_on='num', att2='att2')
         assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
         for x in range(self.upper):
             assert a[x].num == x, x
 
-    def checkTextIndexQWithoutSortOn(self):
+    def testTextIndexQWithoutSortOn(self):
         upper = self.upper
         a = self._catalog(att2='att2')
         assert len(a) == upper, 'length should be %s, its %s'%(upper, len(a))
         for x in range(self.upper):
             assert a[x].data_record_score_ == 1, a[x].data_record_score_
 
-    def checkKeywordIndexWithMinRange(self):
+    def testKeywordIndexWithMinRange(self):
         a = self._catalog(att3='att', att3_usage='range:min')
         assert len(a) == self.upper
 
-    def checkKeywordIndexWithMaxRange(self):
+    def testKeywordIndexWithMaxRange(self):
         a = self._catalog(att3='att35', att3_usage='range:max')
         assert len(a) == self.upper
 
-    def checkKeywordIndexWithMinMaxRangeCorrectSyntax(self):
+    def testKeywordIndexWithMinMaxRangeCorrectSyntax(self):
         a = self._catalog(att3=['att', 'att35'], att3_usage='range:min:max')
         assert len(a) == self.upper
 
-    def checkKeywordIndexWithMinMaxRangeWrongSyntax(self):
+    def testKeywordIndexWithMinMaxRangeWrongSyntax(self):
         """checkKeywordIndex with min/max range wrong syntax - known to fail.
            But because it will fail we need to change the assert statement
            so the unittest will pass *crazy world*
@@ -301,7 +299,7 @@
         a = self._catalog(att3=['att'], att3_usage='range:min:max')
         assert len(a) != self.upper
 
-    def checkCombinedTextandKeywordQuery(self):
+    def testCombinedTextandKeywordQuery(self):
         a = self._catalog(att3='att3', att2='att2')
         assert len(a) == self.upper
 
@@ -315,18 +313,18 @@
     def setUp(self):
         self._vocabulary = Vocabulary.Vocabulary('Vocabulary','Vocabulary', globbing=1)
         self._catalog    = Catalog()
-        self._catalog.addIndex('number',  'FieldIndex')
+        index = FieldIndex('number')
+        self._catalog.addIndex('number',  index)
         self._catalog.addColumn('number')
 
-        for i in range(50000): 
-            if i%1000==0: print i
+        for i in range(5000): 
             obj = objRS(whrandom.randint(0,20000))
             self._catalog.catalogObject(obj,i)
            
         self._catalog.aq_parent = objRS(200)
 
     def testRangeSearch(self):
-        for i in range(1000000): 
+        for i in range(10000): 
 
             m = whrandom.randint(0,20000) 
             n = m + 1000
@@ -337,34 +335,5 @@
                 size = r.number
                 assert m<=size and size<=n , "%d vs [%d,%d]" % (r.number,m,n)
 
-def main():
-    unittest.TextTestRunner().run(test_suite())
-
-
-
-def test_suite():
-
-    ts_cm= (
-         unittest.makeSuite(TestAddDelIndexes,  'check'),
-         unittest.makeSuite(TestCatalogObject,  'check'),
-         unittest.makeSuite(TestAddDelColumn,   'check'),
-         unittest.makeSuite(TestZCatalogObject, 'check')
-    )
-    return unittest.TestSuite(ts_cm)
-
-
-def pdebug():
-    import pdb
-    test_suite()
-
-def debug():
-   test_suite().debug()
- 
-def pdebug():
-    import pdb
-    pdb.run('debug()')
-
-
-if __name__ == '__main__':
-       main()
 
+framework()