Commit 4c6e6ae6 authored by Andreas Jung's avatar Andreas Jung

- some internal work to add support for framework.py

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