Commit 048c040e authored by Tim Peters's avatar Tim Peters

Collector 1831.

The BTree minKey() and maxKey() methods gave a misleading message if no key
satisfying the constraints existed in a non-empty tree.
parent ee4b2b7b
......@@ -5,6 +5,7 @@ Release date: DD-MMM-2005
Following are dates of internal releases (to support ongoing Zope 2
development) since ZODB 3.4's last public release:
- 3.4.1a4 DD-MMM-2005
- 3.4.1a3 02-Jul-2005
- 3.4.1a2 29-Jun-2005
- 3.4.1a1 27-Jun-2005
......@@ -59,8 +60,12 @@ DemoStorage
- The implementation of ``undoLog()`` was wrong in several ways; repaired.
BTrees interface
----------------
BTrees
------
- (3.4.1a4) Collector 1831. The BTree ``minKey()`` and ``maxKey()`` methods
gave a misleading message if no key satisfying the constraints existed in a
non-empty tree.
- (3.4.1a3) Collector 1829. Clarified that the ``minKey()`` and ``maxKey()``
methods raise an exception if no key exists satsifying the constraints.
......
......@@ -1341,6 +1341,7 @@ BTree_maxminKey(BTree *self, PyObject *args, int min)
PyObject *key=0;
Bucket *bucket = NULL;
int offset, rc;
int empty_tree = 1;
UNLESS (PyArg_ParseTuple(args, "|O", &key)) return NULL;
......@@ -1355,6 +1356,7 @@ BTree_maxminKey(BTree *self, PyObject *args, int min)
if ((rc = BTree_findRangeEnd(self, key, min, 0, &bucket, &offset)) <= 0)
{
if (rc < 0) goto err;
empty_tree = 0;
goto empty;
}
PER_UNUSE(self);
......@@ -1392,8 +1394,9 @@ BTree_maxminKey(BTree *self, PyObject *args, int min)
return key;
empty:
PyErr_SetString(PyExc_ValueError, "empty tree");
PyErr_SetString(PyExc_ValueError,
empty_tree ? "empty tree" :
"no key satisfies the conditions");
err:
PER_UNUSE(self);
if (bucket)
......
......@@ -683,6 +683,7 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min)
{
PyObject *key=0;
int rc, offset;
int empty_bucket = 1;
if (args && ! PyArg_ParseTuple(args, "|O", &key)) return NULL;
......@@ -696,6 +697,7 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min)
if ((rc = Bucket_findRangeEnd(self, key, min, 0, &offset)) <= 0)
{
if (rc < 0) return NULL;
empty_bucket = 0;
goto empty;
}
}
......@@ -708,7 +710,9 @@ Bucket_maxminKey(Bucket *self, PyObject *args, int min)
return key;
empty:
PyErr_SetString(PyExc_ValueError, "empty bucket");
PyErr_SetString(PyExc_ValueError,
empty_bucket ? "empty bucket" :
"no key satisfies the conditions");
PER_UNUSE(self);
return NULL;
}
......
......@@ -302,6 +302,20 @@ class MappingBase(Base):
self.assertEqual(t.minKey(3), 3)
self.assertEqual(t.minKey(9), 10)
try:
t.maxKey(t.minKey() - 1)
except ValueError, err:
self.assertEqual(str(err), "no key satisfies the conditions")
else:
self.fail("expected ValueError")
try:
t.minKey(t.maxKey() + 1)
except ValueError, err:
self.assertEqual(str(err), "no key satisfies the conditions")
else:
self.fail("expected ValueError")
def testClear(self):
r = range(100)
for x in r:
......@@ -672,6 +686,20 @@ class NormalSetTests(Base):
self.assert_(t.maxKey() in t)
self.assert_(t.maxKey()+1 not in t)
try:
t.maxKey(t.minKey() - 1)
except ValueError, err:
self.assertEqual(str(err), "no key satisfies the conditions")
else:
self.fail("expected ValueError")
try:
t.minKey(t.maxKey() + 1)
except ValueError, err:
self.assertEqual(str(err), "no key satisfies the conditions")
else:
self.fail("expected ValueError")
def testUpdate(self):
d={}
l=[]
......
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