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