[Zodb-checkins] SVN: ZODB/branches/3.4/ Collector 1831.

Tim Peters tim.one at comcast.net
Tue Jul 5 13:25:53 EDT 2005


Log message for revision 31010:
  Collector 1831.
  
  The BTree minKey() and maxKey() methods gave a misleading message if no key
  satisfying the constraints existed in a non-empty tree.
  

Changed:
  U   ZODB/branches/3.4/NEWS.txt
  U   ZODB/branches/3.4/src/BTrees/BTreeTemplate.c
  U   ZODB/branches/3.4/src/BTrees/BucketTemplate.c
  U   ZODB/branches/3.4/src/BTrees/tests/testBTrees.py

-=-
Modified: ZODB/branches/3.4/NEWS.txt
===================================================================
--- ZODB/branches/3.4/NEWS.txt	2005-07-05 15:13:44 UTC (rev 31009)
+++ ZODB/branches/3.4/NEWS.txt	2005-07-05 17:25:52 UTC (rev 31010)
@@ -5,6 +5,7 @@
 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,9 +60,13 @@
 
 - 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.
 

Modified: ZODB/branches/3.4/src/BTrees/BTreeTemplate.c
===================================================================
--- ZODB/branches/3.4/src/BTrees/BTreeTemplate.c	2005-07-05 15:13:44 UTC (rev 31009)
+++ ZODB/branches/3.4/src/BTrees/BTreeTemplate.c	2005-07-05 17:25:52 UTC (rev 31010)
@@ -1341,6 +1341,7 @@
   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 @@
       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 @@
   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)

Modified: ZODB/branches/3.4/src/BTrees/BucketTemplate.c
===================================================================
--- ZODB/branches/3.4/src/BTrees/BucketTemplate.c	2005-07-05 15:13:44 UTC (rev 31009)
+++ ZODB/branches/3.4/src/BTrees/BucketTemplate.c	2005-07-05 17:25:52 UTC (rev 31010)
@@ -683,6 +683,7 @@
 {
   PyObject *key=0;
   int rc, offset;
+  int empty_bucket = 1;
 
   if (args && ! PyArg_ParseTuple(args, "|O", &key)) return NULL;
 
@@ -696,6 +697,7 @@
       if ((rc = Bucket_findRangeEnd(self, key, min, 0, &offset)) <= 0)
         {
           if (rc < 0) return NULL;
+          empty_bucket = 0;
           goto empty;
         }
     }
@@ -708,7 +710,9 @@
   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;
 }

Modified: ZODB/branches/3.4/src/BTrees/tests/testBTrees.py
===================================================================
--- ZODB/branches/3.4/src/BTrees/tests/testBTrees.py	2005-07-05 15:13:44 UTC (rev 31009)
+++ ZODB/branches/3.4/src/BTrees/tests/testBTrees.py	2005-07-05 17:25:52 UTC (rev 31010)
@@ -302,6 +302,20 @@
         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 @@
         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=[]



More information about the Zodb-checkins mailing list