[Zope3-checkins] CVS: Zope3/src/zodb/btrees/tests - test_btrees.py:1.5
Tim Peters
tim.one@comcast.net
Fri, 21 Feb 2003 12:33:03 -0500
Update of /cvs-repository/Zope3/src/zodb/btrees/tests
In directory cvs.zope.org:/tmp/cvs-serv15826/src/zodb/btrees/tests
Modified Files:
test_btrees.py
Log Message:
Steve Alexander made a strong case to Jim Fulton for extending BTree-ish
range searches to allow for the optional exclusion of an endpoint (like
finding all the items in a BTree with key strictly less than some path-
like string -- it can be very difficult to express this as a "less than
or equal to" range search).
This checkin doesn't implement that yet, but does the large amount of
mostly-mechanical fiddling needed just to give these methods keyword
arguments:
keys()
for
BTree, TreeSet, Bucket, Set
and
values(), items()
for
BTree, Bucket
and
itervalues(), iteritems()
for
BTree
and
iterkeys()
for
BTree, TreeSet
btrees/interfaces.py also documents the new interface (although, again,
it isn't yet implemented).
=== Zope3/src/zodb/btrees/tests/test_btrees.py 1.4 => 1.5 ===
--- Zope3/src/zodb/btrees/tests/test_btrees.py:1.4 Fri Jan 31 14:50:30 2003
+++ Zope3/src/zodb/btrees/tests/test_btrees.py Fri Feb 21 12:33:02 2003
@@ -181,6 +181,10 @@
lst.sort()
self.assertEqual(lst,range(0+x,99-x+1))
+ lst = list(self.t.values(max=99-x, min=0+x))
+ lst.sort()
+ self.assertEqual(lst,range(0+x,99-x+1))
+
def testKeysWorks(self):
for x in range(100):
self.t[x] = x
@@ -194,6 +198,9 @@
lst = self.t.keys(0+x,99-x)
self.assertEqual(list(lst), range(0+x, 99-x+1))
+ lst = self.t.keys(max=99-x, min=0+x)
+ self.assertEqual(list(lst), range(0+x, 99-x+1))
+
self.assertEqual(len(v), 100)
def testItemsWorks(self):
@@ -211,6 +218,13 @@
self.assertEqual(x, (i, 2*i))
i += 1
+ items = list(self.t.items(min=12, max=20))
+ self.assertEqual(items, zip(range(12, 21), range(24, 43, 2)))
+
+ items = list(self.t.iteritems(min=12, max=20))
+ self.assertEqual(items, zip(range(12, 21), range(24, 43, 2)))
+
+
def testDeleteInvalidKeyRaisesKeyError(self):
self.assertRaises(KeyError, self._deletefail)
@@ -282,6 +296,11 @@
self.assertEqual(list(keys), [])
self.assertEqual(list(t.iterkeys(200, 50)), [])
+ keys = t.keys(max=50, min=200)
+ self.assertEqual(len(keys), 0)
+ self.assertEqual(list(keys), [])
+ self.assertEqual(list(t.iterkeys(max=50, min=200)), [])
+
def testSlicing(self):
# Test that slicing of .keys()/.values()/.items() works exactly the
# same way as slicing a Python list with the same contents.
@@ -425,15 +444,15 @@
for key2 in min_mid_max:
for hi in range(key2 - 1, key2 + 2):
goodkeys = [k for k in keys if lo <= k <= hi]
- got = t.iterkeys(lo, hi)
+ got = t.iterkeys(min=lo, max=hi)
self.assertEqual(goodkeys, list(got))
goodvalues = [t[k] for k in goodkeys]
- got = t.itervalues(lo, hi)
+ got = t.itervalues(lo, max=hi)
self.assertEqual(goodvalues, list(got))
gooditems = zip(goodkeys, goodvalues)
- got = t.iteritems(lo, hi)
+ got = t.iteritems(max=hi, min=lo)
self.assertEqual(gooditems, list(got))
def testBadUpdateTupleSize(self):
@@ -509,9 +528,11 @@
def testKeys(self):
t = self.t
r = xrange(1000)
- for x in r: t.insert(x)
+ for x in r:
+ t.insert(x)
diff = lsubtract(t.keys(), r)
- self.assertEqual(diff , [], diff)
+ self.assertEqual(diff, [])
+
def testClear(self):
t = self.t
@@ -573,6 +594,10 @@
self.assertEqual(len(keys), 0)
self.assertEqual(list(keys), [])
+ keys = t.keys(max=50, min=200)
+ self.assertEqual(len(keys), 0)
+ self.assertEqual(list(keys), [])
+
def testSlicing(self):
# Test that slicing of .keys() works exactly the same way as slicing
# a Python list with the same contents.
@@ -881,7 +906,7 @@
# to "go backwards" in the BTree then; if it doesn't, it will
# erroneously claim that the range is empty.
del t[firstkey]
- therange = t.keys(-1, firstkey)
+ therange = t.keys(min=-1, max=firstkey)
self.assertEqual(len(therange), firstkey)
self.assertEqual(list(therange), range(firstkey))