From: Simon P. <sp...@us...> - 2004-02-04 17:02:14
|
Update of /cvsroot/collective/ticle/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8435/tests Modified Files: __init__.py all_tests.py dummyTest.py testCoreObjects.py testIndexer.py testObjectStorage.py testRelationsManager.py testSimpleUIDManager.py testSpeed.py testUIDManager.py util.py Log Message: initial version of plone integration (deletion not working) initial version of constraint manager bug fixes tobias ahlers, sebastian wiemer, markusr reinsch Index: dummyTest.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/dummyTest.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- dummyTest.py 15 Nov 2003 19:05:12 -0000 1.1 +++ dummyTest.py 4 Feb 2004 16:59:46 -0000 1.2 @@ -1,29 +1,29 @@ - -from BTrees.IOBTree import difference, union, intersection -from BTrees.IOBTree import IOSet -import pdb - -a = IOSet() -b = IOSet() -a.update([1,2,3,4]) -b.update([4,5,6,7]) - -print a; print b - -print difference(a,b) -print difference(b,a) - -print union(a,b) -print union(b,a) - -print intersection(a,b) -print intersection(b,a) - -# will have: [1,2,3,4] - -pdb.set_trace() - -g = difference(a,b) -h = union(g, intersection(a,b)) -print h - + +from BTrees.IOBTree import difference, union, intersection +from BTrees.IOBTree import IOSet +import pdb + +a = IOSet() +b = IOSet() +a.update([1,2,3,4]) +b.update([4,5,6,7]) + +print a; print b + +print difference(a,b) +print difference(b,a) + +print union(a,b) +print union(b,a) + +print intersection(a,b) +print intersection(b,a) + +# will have: [1,2,3,4] + +pdb.set_trace() + +g = difference(a,b) +h = union(g, intersection(a,b)) +print h + Index: testIndexer.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testIndexer.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- testIndexer.py 15 Nov 2003 19:05:12 -0000 1.1 +++ testIndexer.py 4 Feb 2004 16:59:46 -0000 1.2 @@ -1,123 +1,123 @@ - -__revision__ = "$Revision$" -__date__ = "$Date$" -__copyright__ = "Copyright (c) 2003 by Simon Pamies" -__full_info__ = "$Id$" - -import unittest - -from ticle.interfaces.indexer import IMetadataIndex, \ - IIndexContainer, IResultItem, IResultListItem, IRelationsIndexer - -from ticle.indexer import RelationsIndexer, MetadataIndex, IndexContainer, \ - ResultItem, ResultListItem - -from ticle.Interface.Verify import verifyClass -from ticle.exception import NotIndexable -from ticle.tests.util import Worm, Wizard, Hobbit, Troll - -class TestIndexer(unittest.TestCase): - - def setUp(self): - self.hobbit = Hobbit() - self.wizard = Wizard() - self.troll = Troll() - self.worm = Worm() - - self._idxer = RelationsIndexer('indexer', None) - - self._idxer.addIndex(MetadataIndex('id')) - self._idxer.addIndex(MetadataIndex('title')) - self._idxer.addIndex(MetadataIndex('getPhysicalPath')) - self._idxer.addIndex(MetadataIndex('hands')) - - def tearDown(self): - self._idxer = None - - def testIndexContainer(self): - self._idxer.addIndex(MetadataIndex('dummy')) - - self.failUnless(self._idxer.hasIndexFor('title')) - self.failUnless(self._idxer.hasIndexFor('dummy')) - self.failIf(self._idxer.hasIndexFor('dummyMethod')) - - self._idxer.removeIndex('dummy') - self.failIf(self._idxer.hasIndexFor('dummy')) - - def testMetadataIndex(self): - i = self._idxer.getIndex('title') - i._check_object(self.troll) - self.failUnlessRaises(NotIndexable, i._check_object, self.worm) - - self.failUnlessRaises(TypeError, i.index_object, self.troll, '33') - self.failUnless(i.index_object(self.troll, 767)) - - self.failUnlessRaises(KeyError, i.unindex_uid, 766) - i.unindex_uid(767) - - def testRelationsManager(self): - uid = self._idxer.index_object(self.wizard) - self._idxer.index_object(self.troll) - self._idxer.index_object(self.worm) - self._idxer.index_object(self.hobbit) - - self._idxer._indexes['id']._data['gandalf'] - guid = self._idxer._indexes['title']._data['the white'] - self.failIf(guid != [uid]) - - # one result - res = self._idxer.search(id='gandalf') - self.failUnless(res()[0].__dict__.has_key('getPhysicalPath') and \ - 'gandalf' in res()[0].__dict__.values()) - - # no result - res = self._idxer.search(id='mordor') - self.failIf(len(res()) != 0, 'Should not find an object with id mordor!') - - # two results - res = self._idxer.search(hands=2) - self.failIf(len(res()) != 2, 'Length of ResultList not == 2, is %s' % len(res())) - self.failUnless(res()[0].__dict__.has_key('hands')) - self.failUnless(res()[0].__dict__.has_key('id')) - - # should yield no results - res = self._idxer.search(id='brobor', hands=0) - self.failIf(len(res()) > 0, 'Found something where nothing should be!') - - # one result - res = self._idxer.search(id='bilbo', title='beutlin') - self.failIf(len(res()) != 1) - self.failUnless(res()[0].__dict__['id'] == 'bilbo') - self.failUnless(res()[0].__dict__.has_key('getPhysicalPath')) - - # no result - res = self._idxer.search(id='bilbo', title='beutlin', hands=244) - self.failIf(len(res()) != 0, 'Hmm... bilbo should never have 244 hands ;-)') - - # Here we throw out the non existing metadata field - # XXX Should we raise an Exception here? - res = self._idxer.search(id='bilbo', not_existing=1) - self.failIf(len(res()) != 1) - - # two results because we searchy with OR - res = self._idxer.search(id='bilbo', title='the white', logical_or=1) - self.failIf(len(res()) != 2, 'OR functionality not functioning!') - - def testImplements(self): - self.failUnless(verifyClass(IIndexContainer, IndexContainer)) - self.failUnless(verifyClass(IRelationsIndexer, RelationsIndexer)) - self.failUnless(verifyClass(IMetadataIndex, MetadataIndex)) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestIndexer)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestIndexer), - )) - -if __name__ == '__main__': - main() + +__revision__ = "$Revision$" +__date__ = "$Date$" +__copyright__ = "Copyright (c) 2003 by Simon Pamies" +__full_info__ = "$Id$" + +import unittest + +from Products.ticle.interfaces.indexer import IMetadataIndex, \ + IIndexContainer, IResultItem, IResultListItem, IRelationsIndexer + +from Products.ticle.indexer import RelationsIndexer, MetadataIndex, IndexContainer, \ + ResultItem, ResultListItem + +from Interface.Verify import verifyClass +from Products.ticle.exception import NotIndexable +from Products.ticle.tests.util import Worm, Wizard, Hobbit, Troll + +class TestIndexer(unittest.TestCase): + + def setUp(self): + self.hobbit = Hobbit() + self.wizard = Wizard() + self.troll = Troll() + self.worm = Worm() + + self._idxer = RelationsIndexer('indexer', None) + + self._idxer.addIndex(MetadataIndex('id')) + self._idxer.addIndex(MetadataIndex('title')) + self._idxer.addIndex(MetadataIndex('getPhysicalPath')) + self._idxer.addIndex(MetadataIndex('hands')) + + def tearDown(self): + self._idxer = None + + def testIndexContainer(self): + self._idxer.addIndex(MetadataIndex('dummy')) + + self.failUnless(self._idxer.hasIndexFor('title')) + self.failUnless(self._idxer.hasIndexFor('dummy')) + self.failIf(self._idxer.hasIndexFor('dummyMethod')) + + self._idxer.removeIndex('dummy') + self.failIf(self._idxer.hasIndexFor('dummy')) + + def testMetadataIndex(self): + i = self._idxer.getIndex('title') + i._check_object(self.troll) + self.failUnlessRaises(NotIndexable, i._check_object, self.worm) + + self.failUnlessRaises(TypeError, i.index_object, self.troll, '33') + self.failUnless(i.index_object(self.troll, 767)) + + self.failUnlessRaises(KeyError, i.unindex_uid, 766) + i.unindex_uid(767) + + def testRelationsManager(self): + uid = self._idxer.index_object(self.wizard) + self._idxer.index_object(self.troll) + self._idxer.index_object(self.worm) + self._idxer.index_object(self.hobbit) + + self._idxer._indexes['id']._data['gandalf'] + guid = self._idxer._indexes['title']._data['the white'] + self.failIf(guid != [uid]) + + # one result + res = self._idxer.search(id='gandalf') + self.failUnless(res()[0].__dict__.has_key('getPhysicalPath') and \ + 'gandalf' in res()[0].__dict__.values()) + + # no result + res = self._idxer.search(id='mordor') + self.failIf(len(res()) != 0, 'Should not find an object with id mordor!') + + # two results + res = self._idxer.search(hands=2) + self.failIf(len(res()) != 2, 'Length of ResultList not == 2, is %s' % len(res())) + self.failUnless(res()[0].__dict__.has_key('hands')) + self.failUnless(res()[0].__dict__.has_key('id')) + + # should yield no results + res = self._idxer.search(id='brobor', hands=0) + self.failIf(len(res()) > 0, 'Found something where nothing should be!') + + # one result + res = self._idxer.search(id='bilbo', title='beutlin') + self.failIf(len(res()) != 1) + self.failUnless(res()[0].__dict__['id'] == 'bilbo') + self.failUnless(res()[0].__dict__.has_key('getPhysicalPath')) + + # no result + res = self._idxer.search(id='bilbo', title='beutlin', hands=244) + self.failIf(len(res()) != 0, 'Hmm... bilbo should never have 244 hands ;-)') + + # Here we throw out the non existing metadata field + # XXX Should we raise an Exception here? + res = self._idxer.search(id='bilbo', not_existing=1) + self.failIf(len(res()) != 1) + + # two results because we searchy with OR + res = self._idxer.search(id='bilbo', title='the white', logical_or=1) + self.failIf(len(res()) != 2, 'OR functionality not functioning!') + + def testImplements(self): + self.failUnless(verifyClass(IIndexContainer, IndexContainer)) + self.failUnless(verifyClass(IRelationsIndexer, RelationsIndexer)) + self.failUnless(verifyClass(IMetadataIndex, MetadataIndex)) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestIndexer)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestIndexer), + )) + +if __name__ == '__main__': + main() Index: testRelationsManager.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testRelationsManager.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- testRelationsManager.py 12 Jan 2004 09:55:13 -0000 1.4 +++ testRelationsManager.py 4 Feb 2004 16:59:46 -0000 1.5 @@ -1,75 +1,68 @@ - -__revision__ = "$Revision$" -__date__ = "$Date$" -__copyright__ = "Copyright (c) 2003 by Simon Pamies" -__full_info__ = "$Id$" - -import unittest - -from ticle.interfaces.relationsmanager import IRelationsManager -from ticle.relationsmanager import RelationsManager -from ticle.Interface.Verify import verifyClass - -from ticle.core import TicleCore -from ticle.tests.util import Wizard, Hobbit, Troll -from ticle.coreobjects import TripleItem - -class TestRelationsManager(unittest.TestCase): - - def setUp(self): - self.core = TicleCore('__dummy__') - self.wizard = Wizard() - self.wizard.id = self.core.getUIDManager().generateUID() - self.hobbit = Hobbit() - self.hobbit.id = self.core.getUIDManager().generateUID() - self.isLeadBy = TripleItem(self.core.getUIDManager().generateUID(), 'isLeadBy') - - def tearDown(self): - self.core = None - - def testAddTriple(self): - link_uid = self.core.getRelationsManager().addTriple( \ - self.isLeadBy.id, self.hobbit.id, self.wizard.id) - - self.failUnless(link_uid) - res = list(self.core.getRelationsManager().getTargetsFor(self.hobbit.id)) - - self.failUnless(res) - self.failUnless(res[0].id == link_uid) - self.failUnless(res[0].getTarget == self.wizard.id) - self.failUnless(res[0].getSource == self.hobbit.id) - self.failUnless(res[0].getRelationType == self.isLeadBy.id) - - def testExistsTriple(self): - link_uid = self.core.getRelationsManager().addTriple( \ - self.isLeadBy.id, self.wizard.id, self.hobbit.id) - - self.failUnless(self.core.getRelationsManager().existsTriple( \ - self.isLeadBy.id, self.wizard.id, self.hobbit.id)) - - self.failIf(self.core.getRelationsManager().existsTriple( \ - self.isLeadBy.id, self.wizard.id, self.wizard.id)) - - self.core.getRelationsManager().unlink( \ - self.isLeadBy.id, self.wizard.id, self.hobbit.id) - - self.failIf(self.core.getRelationsManager().existsTriple( \ - self.isLeadBy.id, self.wizard.id, self.hobbit.id)) - - def testImplements(self): - self.failUnless(verifyClass(IRelationsManager, RelationsManager)) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestRelationsManager)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestRelationsManager), - )) - -if __name__ == '__main__': - main() - + +__revision__ = "$Revision$" +__date__ = "$Date$" +__copyright__ = "Copyright (c) 2003 by Simon Pamies" +__full_info__ = "$Id$" + +import unittest + +from Products.ticle.interfaces.relationsmanager import IRelationsManager +from Products.ticle.relationsmanager import RelationsManager +from Interface.Verify import verifyClass + +from Products.ticle.core import TicleCore +from Products.ticle.tests.util import Wizard, Hobbit, Troll + +class TestRelationsManager(unittest.TestCase): + + def setUp(self): + self.core = TicleCore('__dummy__') + self.rm = self.core.getRelationsManager() + + self.wizard = self.rm.addAtomRelation() + self.hobbit = self.rm.addAtomRelation() + self.isLeadBy = self.rm.addAtomRelation() + + def tearDown(self): + self.core = None + + def testAddRelation(self): + relation = self.rm.addRelation( self.isLeadBy, self.hobbit, self.wizard) + + self.failUnless(relation) + res = list(self.rm.getRelations([],self.hobbit.id,self.wizard.id)) + + self.failUnless(res) + self.failUnless(res[0].id == relation.id) + self.failUnless(res[0].uid3 == self.wizard.id) + self.failUnless(res[0].uid2 == self.hobbit.id) + self.failUnless(res[0].uid1 == self.isLeadBy.id) + + def testExistsRelation(self): + link_uid = self.rm.addRelation(self.isLeadBy, self.wizard, self.hobbit) + + self.failUnless(self.rm.existsRelation( self.isLeadBy.id, self.wizard.id, self.hobbit.id)) + + self.failIf(self.rm.existsRelation(self.isLeadBy.id, self.wizard.id, self.wizard.id)) + + self.rm.deleteRelations(self.isLeadBy, self.wizard, self.hobbit) + + self.failIf(self.rm.existsRelation(self.isLeadBy.id, self.wizard.id, self.hobbit.id)) + + def testImplements(self): + self.failUnless(verifyClass(IRelationsManager, RelationsManager)) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestRelationsManager)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestRelationsManager), + )) + +if __name__ == '__main__': + main() + Index: testCoreObjects.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testCoreObjects.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- testCoreObjects.py 15 Nov 2003 19:05:12 -0000 1.1 +++ testCoreObjects.py 4 Feb 2004 16:59:46 -0000 1.2 @@ -1,45 +1,45 @@ - -__revision__ = "$Revision$" -__date__ = "$Date$" -__copyright__ = "Copyright (c) 2003 by Simon Pamies" -__full_info__ = "$Id$" - -import unittest - -from ticle.interfaces.linkobject import ITriple -from ticle.coreobjects import Triple, TripleItem - -from ticle.Interface.Verify import verifyClass - -class TestCoreObjects(unittest.TestCase): - - def setUp(self): - pass - - def tearDown(self): - pass - - def testLinkObject(self): - ob = Triple('fakeuid', TripleItem('_','isAuthorOf'), TripleItem('_','source'), TripleItem('_','target')) - self.failIf(ob.getLinkUID() != 'fakeuid') - self.failIf(ob.getRelationType() != 'isAuthorOf') - self.failIf(ob.getSource() != 'source') - self.failIf(ob.getTarget() != 'target') - - def testImplements(self): - self.failUnless(verifyClass(ITriple, Triple)) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestCoreObjects)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestCoreObjects), - )) - -if __name__ == '__main__': - main() - + +__revision__ = "$Revision$" +__date__ = "$Date$" +__copyright__ = "Copyright (c) 2003 by Simon Pamies" +__full_info__ = "$Id$" + +import unittest + +from Products.ticle.interfaces.linkobject import ITriple +from Products.ticle.coreobjects import Triple + +from Interface.Verify import verifyClass + +class TestCoreObjects(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def testTripleObject(self): + ob = Triple('fakeuid', 'isAuthorOf', 'source', 'target') + self.failIf(ob.__dict__["id"] != 'fakeuid') + self.failIf(ob.__dict__["uid1"] != 'isAuthorOf') + self.failIf(ob.__dict__["uid2"] != 'source') + self.failIf(ob.__dict__["uid3"] != 'target') + + def testImplements(self): + self.failUnless(verifyClass(ITriple, Triple)) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestCoreObjects)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestCoreObjects), + )) + +if __name__ == '__main__': + main() + Index: all_tests.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/all_tests.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- all_tests.py 20 Jan 2004 19:55:38 -0000 1.6 +++ all_tests.py 4 Feb 2004 16:59:46 -0000 1.7 @@ -1,36 +1,36 @@ - -# check for PYTHONPATH setting -import sys, os -pt = sys.path - -# splitting path -acdir, res = os.getcwd().split('/'), [] -for item in acdir: - if item != 'ticle': - res.append(item) - - else: break - -res = '/'.join(res) -if res not in pt: - print >> sys.stderr, '\nInserting %s into the PYTHONPATH...' % res - sys.path.append(res) - - from ticle.zope_checker import check_for_zodb - check_for_zodb() - -from unittest import main -from ticle.tests.util import build_test_suite - -tests = ['testUIDManager', - 'testObjectStorage', - 'testSimpleUIDManager', - 'testCoreObjects', - 'testRelationsManager', - 'testIndexer'] - -def test_suite(): - return build_test_suite('ticle.tests', tests) - -if __name__ == '__main__': - main(defaultTest = 'test_suite') + +# check for PYTHONPATH setting +import sys, os +pt = sys.path + +# splitting path +acdir, res = os.getcwd().split('/'), [] +for item in acdir: + if item != 'ticle': + res.append(item) + + else: break + +res = '/'.join(res) +if res not in pt: + print >> sys.stderr, '\nInserting %s into the PYTHONPATH...' % res + sys.path.append(res) + + from ticle.zope_checker import check_for_zodb + check_for_zodb() + +from unittest import main +from ticle.tests.util import build_test_suite + +tests = ['testUIDManager', + 'testObjectStorage', + 'testSimpleUIDManager', + 'testCoreObjects', + 'testRelationsManager', + 'testIndexer'] + +def test_suite(): + return build_test_suite('ticle.tests', tests) + +if __name__ == '__main__': + main(defaultTest = 'test_suite') Index: util.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/util.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- util.py 15 Nov 2003 19:05:12 -0000 1.2 +++ util.py 4 Feb 2004 16:59:46 -0000 1.3 @@ -1,67 +1,67 @@ - -from unittest import TestSuite -from sys import modules -from ZODB.cPersistence import Persistent - -# taken from CMFCore.tests.base.utils -def build_test_suite(package_name,module_names,required=1): - """ - Utlitity for building a test suite from a package name - and a list of modules. - - If required is false, then ImportErrors will simply result - in that module's tests not being added to the returned - suite. - """ - - suite = TestSuite() - try: - for name in module_names: - the_name = package_name+'.'+name - __import__(the_name,globals(),locals()) - suite.addTest(modules[the_name].test_suite()) - - except ImportError: - if required: - raise - - return suite - -class Hobbit(Persistent): - - def __init__(self): - self.id = 'bilbo' - self.title = 'beutlin' - self.hands = 2 - - def getPhysicalPath(self): - return '/auenland/1/' - -class Wizard(Persistent): - - def __init__(self): - self.id = 'gandalf' - self.title = 'the white' - self.hands = 2 - - def getPhysicalPath(self): - return '/where/the/sun/shines/' - -class Troll(Persistent): - - def __init__(self): - self.id = 'brobor' - self.title = 'the slayer' - self.hands = 1 - - def getPhysicalPath(self): - return '/dark/hole/under/isengard' - -class Worm(Persistent): - - def __init__(self): - self.id = 'wyrm' - self.hands = 0 - - def getPhysicalPath(self): - return '/dark/hole/under/isengard' + +from unittest import TestSuite +from sys import modules +from ZODB.cPersistence import Persistent + +# taken from CMFCore.tests.base.utils +def build_test_suite(package_name,module_names,required=1): + """ + Utlitity for building a test suite from a package name + and a list of modules. + + If required is false, then ImportErrors will simply result + in that module's tests not being added to the returned + suite. + """ + + suite = TestSuite() + try: + for name in module_names: + the_name = package_name+'.'+name + __import__(the_name,globals(),locals()) + suite.addTest(modules[the_name].test_suite()) + + except ImportError: + if required: + raise + + return suite + +class Hobbit(Persistent): + + def __init__(self): + self.id = 'bilbo' + self.title = 'beutlin' + self.hands = 2 + + def getPhysicalPath(self): + return '/auenland/1/' + +class Wizard(Persistent): + + def __init__(self): + self.id = 'gandalf' + self.title = 'the white' + self.hands = 2 + + def getPhysicalPath(self): + return '/where/the/sun/shines/' + +class Troll(Persistent): + + def __init__(self): + self.id = 'brobor' + self.title = 'the slayer' + self.hands = 1 + + def getPhysicalPath(self): + return '/dark/hole/under/isengard' + +class Worm(Persistent): + + def __init__(self): + self.id = 'wyrm' + self.hands = 0 + + def getPhysicalPath(self): + return '/dark/hole/under/isengard' Index: testUIDManager.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testUIDManager.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- testUIDManager.py 15 Nov 2003 19:05:12 -0000 1.3 +++ testUIDManager.py 4 Feb 2004 16:59:46 -0000 1.4 @@ -1,61 +1,61 @@ - -import unittest - -from ticle.Interface.Verify import verifyClass -from ticle.interfaces.uid import IIMSUIDManager - -from ticle.uid import IMSUIDManager - -class TestUIDManager(unittest.TestCase): - - def setUp(self): - self.uids = {} - self.manager = IMSUIDManager('___', None) - - def tearDown(self): - del self.uids - del self.manager - - def testNID(self): - self.failUnlessEqual(self.manager.getNID(), 'URN:' + self.manager._default_nid) - self.manager._setNID('TEST-NID') - self.failUnlessEqual(self.manager.getNID(), 'URN:TEST-NID') - - def testGenUID(self): - uuid = self.manager._gen_uid() - self.failUnless(uuid) - - uuid = self.manager._gen_uid(base64=1) - self.failUnless(uuid) - - def testSourcedUID(self): - uid_a = self.manager.getSourcedUID('DUNS', - '123456789') - - uid_b = self.manager.getSourcedUID('DUNS', - '123456789', - 'ISBN') - - uid_c = self.manager.generateUID() - - self.failUnless(self.manager.isSourced(uid_a)) - self.failUnless(self.manager.isSourced(uid_b)) - self.failIf(self.manager.isSourced(uid_c)) - - def testImplements(self): - self.failUnless(verifyClass(IIMSUIDManager, IMSUIDManager)) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestUIDManager)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestUIDManager), - )) - -if __name__ == '__main__': - main() - + +import unittest + +from Interface.Verify import verifyClass +from Products.ticle.interfaces.uid import IIMSUIDManager + +from Products.ticle.uid import IMSUIDManager + +class TestUIDManager(unittest.TestCase): + + def setUp(self): + self.uids = {} + self.manager = IMSUIDManager('___', None) + + def tearDown(self): + del self.uids + del self.manager + + def testNID(self): + self.failUnlessEqual(self.manager.getNID(), 'URN:' + self.manager._default_nid) + self.manager._setNID('TEST-NID') + self.failUnlessEqual(self.manager.getNID(), 'URN:TEST-NID') + + def testGenUID(self): + uuid = self.manager._gen_uid() + self.failUnless(uuid) + + uuid = self.manager._gen_uid(base64=1) + self.failUnless(uuid) + + def testSourcedUID(self): + uid_a = self.manager.getSourcedUID('DUNS', + '123456789') + + uid_b = self.manager.getSourcedUID('DUNS', + '123456789', + 'ISBN') + + uid_c = self.manager.generateUID() + + self.failUnless(self.manager.isSourced(uid_a)) + self.failUnless(self.manager.isSourced(uid_b)) + self.failIf(self.manager.isSourced(uid_c)) + + def testImplements(self): + self.failUnless(verifyClass(IIMSUIDManager, IMSUIDManager)) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestUIDManager)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestUIDManager), + )) + +if __name__ == '__main__': + main() + Index: __init__.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/__init__.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- __init__.py 11 Oct 2003 15:26:53 -0000 1.1 +++ __init__.py 4 Feb 2004 16:59:46 -0000 1.2 @@ -1 +1 @@ - + Index: testObjectStorage.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testObjectStorage.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- testObjectStorage.py 3 Dec 2003 08:37:41 -0000 1.5 +++ testObjectStorage.py 4 Feb 2004 16:59:46 -0000 1.6 @@ -1,120 +1,120 @@ - -__revision__ = "$Revision$" -__date__ = "$Date$" -__copyright__ = "Copyright (c) 2003 by Simon Pamies" -__full_info__ = "$Id$" - -import unittest - -from ticle.Interface.Verify import verifyClass -from ticle.interfaces.storage import IObjectStorage, IRelationsStorage - -from ticle.uid import IMSUIDManager -from ticle.exception import StorageException -from ticle.objectstorage import ObjectStorage, RelationsStorage -from ticle.coreobjects import Triple -from ticle.core import TicleCore - -import ZODB -from ZODB.FileStorage import FileStorage -from ZODB.cPersistence import Persistent - -class DummyObject(Persistent): - - def __init__(self, id): - self.id = id - -class TripleDummy(Triple): pass - -class TestObjectStorage(unittest.TestCase): - - # when set to 1 tests causing very heavy - # load are executed... - __heavy_load__ = 0 - __load_range__ = 10000 - - def setUp(self): - self.db = ZODB.DB(FileStorage('test.fs')) - self.root = self.db.open().root() - - try: - from ticle.core import TicleCore - self.cr = TicleCore('__') - self.uid_manager = IMSUIDManager('dummyuid', self.cr) - self.root['storage'] = ObjectStorage('storage', self.cr) - get_transaction().commit() - except: - self.tearDownZODB() - raise - - def tearDownZODB(self): - self.db.close() - self.root = None - self.db = None - self.cr = None - - import os - os.remove('test.fs') - os.remove('test.fs.index') - os.remove('test.fs.tmp') - - def tearDown(self): - self.tearDownZODB() - - def testStore(self): - ob = DummyObject(self.uid_manager.generateUID()) - self.root['storage'].storeObject(ob) - get_transaction().commit() - - # should be changed to an UID - self.failIf(ob.id == 'dummy') - - def testRetrieval(self): - ob = DummyObject(self.uid_manager.generateUID()) - uid = self.root['storage'].storeObject(ob) - get_transaction().commit() - idd = self.root['storage'].retrieveObject(uid).id - self.failIf(idd != uid, '%s is not %s' % (idd, uid)) - self.failUnlessRaises(KeyError, \ - self.root['storage'].retrieveObject, 'DummyUID') - - def testRemoval(self): - ob = DummyObject(self.uid_manager.generateUID()) - uid = self.root['storage'].storeObject(ob) - get_transaction().commit() - self.root['storage'].removeObject(uid) - get_transaction().commit() - self.failUnlessRaises(KeyError, \ - self.root['storage'].retrieveObject, uid) - - def testRelationsStorage(self): - cr = TicleCore('__core__') - st = cr.getRelationsStorage() - self.failUnlessRaises(StorageException, st.storeObject, DummyObject('__')) - uid = st.storeObject(TripleDummy('dummyobject', 'type', 'source', 'target')) - - # nothing should happen here - st.removeObject(uid) - - def testImplements(self): - self.failUnless(verifyClass(IObjectStorage, ObjectStorage)) - self.failUnless(verifyClass(IRelationsStorage, RelationsStorage)) - - def testHeavyLoad(self): - # XXX to be done - if TestObjectStorage.__heavy_load__: - bt = ObjectStorage('heavy_storage', self.uid_manager) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestObjectStorage)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestObjectStorage), - )) - -if __name__ == '__main__': - main() + +__revision__ = "$Revision$" +__date__ = "$Date$" +__copyright__ = "Copyright (c) 2003 by Simon Pamies" +__full_info__ = "$Id$" + +import unittest + +from Interface.Verify import verifyClass +from Products.ticle.interfaces.storage import IObjectStorage, IRelationsStorage + +from Products.ticle.uid import IMSUIDManager +from Products.ticle.exception import StorageException +from Products.ticle.objectstorage import ObjectStorage, RelationsStorage +from Products.ticle.coreobjects import Triple +from Products.ticle.core import TicleCore + +import ZODB +from ZODB.FileStorage import FileStorage +from ZODB.cPersistence import Persistent + +class DummyObject(Persistent): + + def __init__(self, id): + self.id = id + +class TripleDummy(Triple): pass + +class TestObjectStorage(unittest.TestCase): + + # when set to 1 tests causing very heavy + # load are executed... + __heavy_load__ = 0 + __load_range__ = 10000 + + def setUp(self): + self.db = ZODB.DB(FileStorage('test.fs')) + self.root = self.db.open().root() + + try: + from Products.ticle.core import TicleCore + self.cr = TicleCore('__') + self.uid_manager = IMSUIDManager('dummyuid', self.cr) + self.root['storage'] = ObjectStorage('storage', self.cr) + get_transaction().commit() + except: + self.tearDownZODB() + raise + + def tearDownZODB(self): + self.db.close() + self.root = None + self.db = None + self.cr = None + + import os + os.remove('test.fs') + os.remove('test.fs.index') + os.remove('test.fs.tmp') + + def tearDown(self): + self.tearDownZODB() + + def testStore(self): + ob = DummyObject(self.uid_manager.generateUID()) + self.root['storage'].storeObject(ob) + get_transaction().commit() + + # should be changed to an UID + self.failIf(ob.id == 'dummy') + + def testRetrieval(self): + ob = DummyObject(self.uid_manager.generateUID()) + uid = self.root['storage'].storeObject(ob).id + get_transaction().commit() + idd = self.root['storage'].retrieveObject(uid).id + self.failIf(idd != uid, '%s is not %s' % (idd, uid)) + self.failUnlessRaises(KeyError, \ + self.root['storage'].retrieveObject, 'DummyUID') + + def testRemoval(self): + ob = DummyObject(self.uid_manager.generateUID()) + uid = self.root['storage'].storeObject(ob).id + get_transaction().commit() + self.root['storage'].removeObject(uid) + get_transaction().commit() + self.failUnlessRaises(KeyError, \ + self.root['storage'].retrieveObject, uid) + + def testRelationsStorage(self): + cr = TicleCore('__core__') + st = cr.getRelationsStorage() + self.failUnlessRaises(StorageException, st.storeObject, DummyObject('__')) + uid = st.storeObject(TripleDummy('dummyobject', 'type', 'source', 'target')) + + # nothing should happen here + st.removeObject(uid) + + def testImplements(self): + self.failUnless(verifyClass(IObjectStorage, ObjectStorage)) + self.failUnless(verifyClass(IRelationsStorage, RelationsStorage)) + + def testHeavyLoad(self): + # XXX to be done + if TestObjectStorage.__heavy_load__: + bt = ObjectStorage('heavy_storage', self.uid_manager) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestObjectStorage)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestObjectStorage), + )) + +if __name__ == '__main__': + main() Index: testSimpleUIDManager.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testSimpleUIDManager.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- testSimpleUIDManager.py 15 Nov 2003 19:05:12 -0000 1.3 +++ testSimpleUIDManager.py 4 Feb 2004 16:59:46 -0000 1.4 @@ -1,67 +1,67 @@ - -import unittest - -from ticle.Interface.Verify import verifyClass -from ticle.interfaces.uid import IIMSUIDManager - -from ticle.uid import IMSUIDManager - -class eIMs(IMSUIDManager): - - def _gen_uid(self, base64=0): - from ticle.uidgen.simple import SimpleUID - return SimpleUID.make() - -class TestSimpleUIDManager(unittest.TestCase): - - def setUp(self): - self.uids = {} - self.manager = eIMs('____', None) - - def tearDown(self): - del self.uids - del self.manager - - def testNID(self): - self.failUnlessEqual(self.manager.getNID(), 'URN:' + self.manager._default_nid) - self.manager._setNID('TEST-NID') - self.failUnlessEqual(self.manager.getNID(), 'URN:TEST-NID') - - def testGenUID(self): - uuid = self.manager._gen_uid() - self.failUnless(uuid) - - uuid = self.manager._gen_uid(base64=1) - self.failUnless(uuid) - - def testSourcedUID(self): - uid_a = self.manager.getSourcedUID('DUNS', - '123456789') - - uid_b = self.manager.getSourcedUID('DUNS', - '123456789', - 'ISBN') - - uid_c = self.manager.generateUID() - - self.failUnless(self.manager.isSourced(uid_a)) - self.failUnless(self.manager.isSourced(uid_b)) - self.failIf(self.manager.isSourced(uid_c)) - - def testImplements(self): - self.failUnless(verifyClass(IIMSUIDManager, IMSUIDManager)) - -def main(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(TestSimpleUIDManager)) - runner = unittest.TextTestRunner() - runner.run(suite) - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(TestSimpleUIDManager), - )) - -if __name__ == '__main__': - main() - + +import unittest + +from Interface.Verify import verifyClass +from Products.ticle.interfaces.uid import IIMSUIDManager + +from Products.ticle.uid import IMSUIDManager + +class eIMs(IMSUIDManager): + + def _gen_uid(self, base64=0): + from Products.ticle.uidgen.simple import SimpleUID + return SimpleUID.make() + +class TestSimpleUIDManager(unittest.TestCase): + + def setUp(self): + self.uids = {} + self.manager = eIMs('____', None) + + def tearDown(self): + del self.uids + del self.manager + + def testNID(self): + self.failUnlessEqual(self.manager.getNID(), 'URN:' + self.manager._default_nid) + self.manager._setNID('TEST-NID') + self.failUnlessEqual(self.manager.getNID(), 'URN:TEST-NID') + + def testGenUID(self): + uuid = self.manager._gen_uid() + self.failUnless(uuid) + + uuid = self.manager._gen_uid(base64=1) + self.failUnless(uuid) + + def testSourcedUID(self): + uid_a = self.manager.getSourcedUID('DUNS', + '123456789') + + uid_b = self.manager.getSourcedUID('DUNS', + '123456789', + 'ISBN') + + uid_c = self.manager.generateUID() + + self.failUnless(self.manager.isSourced(uid_a)) + self.failUnless(self.manager.isSourced(uid_b)) + self.failIf(self.manager.isSourced(uid_c)) + + def testImplements(self): + self.failUnless(verifyClass(IIMSUIDManager, IMSUIDManager)) + +def main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestSimpleUIDManager)) + runner = unittest.TextTestRunner() + runner.run(suite) + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(TestSimpleUIDManager), + )) + +if __name__ == '__main__': + main() + Index: testSpeed.py =================================================================== RCS file: /cvsroot/collective/ticle/tests/testSpeed.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- testSpeed.py 12 Jan 2004 09:55:13 -0000 1.2 +++ testSpeed.py 4 Feb 2004 16:59:46 -0000 1.3 @@ -1,99 +1,99 @@ - -# Compare Speed between BTree search -# and catalogizd search... - -""" -LOG: - -Starting creation of 500000 objects... -Finished creation of objects! -Average Storage Creation Time: 0.00014007091403 -Average Catalog Indexing Time: 0.00320337156371 - -Maximal Storage Time needed: 3.82981288433 -Maximal Catalog Time needed: 347.197054982 - -Minimal Storage Time needed: -0.119868993759 -Minimal Catalog Time needed: -0.386137962341 - -Storage Load time for object number 400000: 0.240200996399 -Catalog Load time for object number 400000: 0.323825001717 -""" - -import ZODB -from ZODB.cPersistence import Persistent -from Products.ZCatalog.Catalog import Catalog -from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex -from ticle.objectstorage import ObjectStorage -from ticle.uid import IMSUIDManager -from time import time - -obnum = 500000 -idx = 400000 - -def computeTimeList(xlist): - from copy import copy - ll = copy(xlist) - res = float(1) - ln = len(ll) - for t in range(len(ll)): - res += float(ll.pop()) - - return float(res) / float(ln) - -class DummyObject(Persistent): - - def __init__(self, id): - self.id = id - -if __name__ == '__main__': - - from ticle.core import TicleCore - uu = TicleCore('dummy') - bt = uu.getObjectStorage() - - ct = Catalog() - fi = FieldIndex('id') - ct.addColumn('id') - ct.addIndex('id', fi) - - # create objects and store - # them into BTree and index them - # in the Catalog - print "Starting creation of %s objects..." % obnum - average_storage = [0] - average_catalog = [0] - gggid = '' - for i in range(obnum): - gid = uu.getUIDManager().generateUID() - ob = DummyObject(i) - start = time() - - uid = bt.storeObject(ob) - if i == 400000: - gggid = uid - - di = time() - start - average_storage.append(di) - start = time() - ct.catalogObject(ob, i) - di = time() - start - average_catalog.append(di) - - print "Finished creation of objects!" - print "Average Storage Creation Time: " + str(computeTimeList(average_storage)) - print "Average Catalog Indexing Time: " + str(computeTimeList(average_catalog)) - print "\nMaximal Storage Time needed: " + str(max(average_storage)) - print "Maximal Catalog Time needed: " + str(max(average_catalog)) - print "\nMinimal Storage Time needed: " + str(min(average_storage)) - print "Minimal Catalog Time needed: " + str(min(average_catalog)) - - # Searching for an object - start = time() - bt.retrieveObject(gggid) - di = time() - start - print "\nStorage Load time for object number %s: %s" % (idx, di) - start = time() - ct.searchResults(id=idx) - di = time() - start - print "Catalog Load time for object number %s: %s" % (idx, di) + +# Compare Speed between BTree search +# and catalogizd search... + +""" +LOG: + +Starting creation of 500000 objects... +Finished creation of objects! +Average Storage Creation Time: 0.00014007091403 +Average Catalog Indexing Time: 0.00320337156371 + +Maximal Storage Time needed: 3.82981288433 +Maximal Catalog Time needed: 347.197054982 + +Minimal Storage Time needed: -0.119868993759 +Minimal Catalog Time needed: -0.386137962341 + +Storage Load time for object number 400000: 0.240200996399 +Catalog Load time for object number 400000: 0.323825001717 +""" + +import ZODB +from ZODB.cPersistence import Persistent +from Products.ZCatalog.Catalog import Catalog +from Products.PluginIndexes.FieldIndex.FieldIndex import FieldIndex +from ticle.objectstorage import ObjectStorage +from ticle.uid import IMSUIDManager +from time import time + +obnum = 500000 +idx = 400000 + +def computeTimeList(xlist): + from copy import copy + ll = copy(xlist) + res = float(1) + ln = len(ll) + for t in range(len(ll)): + res += float(ll.pop()) + + return float(res) / float(ln) + +class DummyObject(Persistent): + + def __init__(self, id): + self.id = id + +if __name__ == '__main__': + + from ticle.core import TicleCore + uu = TicleCore('dummy') + bt = uu.getObjectStorage() + + ct = Catalog() + fi = FieldIndex('id') + ct.addColumn('id') + ct.addIndex('id', fi) + + # create objects and store + # them into BTree and index them + # in the Catalog + print "Starting creation of %s objects..." % obnum + average_storage = [0] + average_catalog = [0] + gggid = '' + for i in range(obnum): + gid = uu.getUIDManager().generateUID() + ob = DummyObject(i) + start = time() + + uid = bt.storeObject(ob) + if i == 400000: + gggid = uid + + di = time() - start + average_storage.append(di) + start = time() + ct.catalogObject(ob, i) + di = time() - start + average_catalog.append(di) + + print "Finished creation of objects!" + print "Average Storage Creation Time: " + str(computeTimeList(average_storage)) + print "Average Catalog Indexing Time: " + str(computeTimeList(average_catalog)) + print "\nMaximal Storage Time needed: " + str(max(average_storage)) + print "Maximal Catalog Time needed: " + str(max(average_catalog)) + print "\nMinimal Storage Time needed: " + str(min(average_storage)) + print "Minimal Catalog Time needed: " + str(min(average_catalog)) + + # Searching for an object + start = time() + bt.retrieveObject(gggid) + di = time() - start + print "\nStorage Load time for object number %s: %s" % (idx, di) + start = time() + ct.searchResults(id=idx) + di = time() - start + print "Catalog Load time for object number %s: %s" % (idx, di) |