[Zodb-checkins] CVS: Zope/lib/python/ZODB/tests - testfsIndex.py:1.4.2.1

Guido van Rossum guido@python.org
Wed, 13 Feb 2002 11:24:07 -0500


Update of /cvs-repository/Zope/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv29969/lib/python/ZODB/tests

Added Files:
      Tag: Zope-2_5-branch
	testfsIndex.py 
Log Message:
Add the fsIndex feature (merge from trunk).  This adds a new BTree
variant, fsBTree, a module fsIndex.py that uses it, and some changes
to FileStorage.py that use fsIndex.


=== Added File Zope/lib/python/ZODB/tests/testfsIndex.py ===

import unittest, sys
from ZODB.fsIndex import fsIndex
from ZODB.utils import p64


class Test(unittest.TestCase):

    def testInserts(self):
        index=fsIndex()

        for i in range(200):
            index[p64(i*1000)]=(i*1000L+1)

        for i in range(0,200):
            self.assertEqual((i,index[p64(i*1000)]), (i,(i*1000L+1)))
            
        self.assertEqual(len(index), 200)

        key=p64(2000)

        self.assertEqual(index.get(key), 2001)

        key=p64(2001)
        self.assertEqual(index.get(key), None)
        self.assertEqual(index.get(key, ''), '')

        # self.failUnless(len(index._data) > 1)

    def testUpdate(self):
        index=fsIndex()
        d={}

        for i in range(200):
            d[p64(i*1000)]=(i*1000L+1)

        index.update(d)

        for i in range(400,600):
            d[p64(i*1000)]=(i*1000L+1)
        
        index.update(d)

        for i in range(100, 500):
            d[p64(i*1000)]=(i*1000L+2)
            
        index.update(d)

        self.assertEqual(index.get(p64(2000)), 2001)
        self.assertEqual(index.get(p64(599000)), 599001)
        self.assertEqual(index.get(p64(399000)), 399002)
        self.assertEqual(len(index), 600)


def test_suite():
    loader=unittest.TestLoader()
    return loader.loadTestsFromTestCase(Test)

if __name__=='__main__':
    unittest.TextTestRunner().run(test_suite())