[Zodb-checkins] CVS: Packages/ZODB/tests - testfsIndex.py:1.6.34.2
Tim Peters
tim.one at comcast.net
Thu Feb 24 17:41:25 EST 2005
Update of /cvs-repository/Packages/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv2861/ZODB/tests
Modified Files:
Tag: Zope-2_7-branch
testfsIndex.py
Log Message:
Give fsIndex an efficient maxKey() implementation.
This will (in a later checkin) be used to give FileStorage an "obviously
correct" way to determine the largest oid used in an .fs.index file.
=== Packages/ZODB/tests/testfsIndex.py 1.6.34.1 => 1.6.34.2 ===
--- Packages/ZODB/tests/testfsIndex.py:1.6.34.1 Mon Sep 15 17:26:57 2003
+++ Packages/ZODB/tests/testfsIndex.py Thu Feb 24 17:41:25 2005
@@ -12,6 +12,8 @@
#
##############################################################################
import unittest, sys
+import random
+
from ZODB.fsIndex import fsIndex
from ZODB.utils import p64
@@ -63,6 +65,21 @@
self.assertEqual(index.get(p64(399000)), 399002)
self.assertEqual(len(index), 600)
+ def testMaxKey(self):
+ index = fsIndex()
+
+ # An empty index should complain.
+ self.assertRaises(ValueError, index.maxKey)
+
+ # Now build up a tree with random values, and check maxKey at each
+ # step.
+ correct_max = "" # smaller than anything we'll add
+ for i in range(1000):
+ key = p64(random.randrange(100000000))
+ index[key] = i
+ correct_max = max(correct_max, key)
+ index_max = index.maxKey()
+ self.assertEqual(index_max, correct_max)
def test_suite():
loader=unittest.TestLoader()
More information about the Zodb-checkins
mailing list