Commit 912b0a2e authored by Tres Seaver's avatar Tres Seaver

Make pure-Python impl. of 'OOBTree.byValue' match semantics of C impl.

Items must be in reversed-sorted order.
parent 2472f6b5
......@@ -1171,7 +1171,8 @@ class Tree(_Tree):
return iter(self.items(min, max, excludemin, excludemax))
def byValue(self, min):
return sorted((v, k) for (k, v) in self.iteritems() if v >= min)
return reversed(
sorted((v, k) for (k, v) in self.iteritems() if v >= min))
def insert(self, key, value):
return bool(self._set(key, value, True)[0])
......
......@@ -99,9 +99,15 @@ class OOSetPyTest(ExtendedSetTests, unittest.TestCase):
class OOBTreeTest(BTreeTests, unittest.TestCase):
def _makeOne(self):
def _makeOne(self, *args):
from BTrees.OOBTree import OOBTree
return OOBTree()
return OOBTree(*args)
def test_byValue(self):
ITEMS = [(y, x) for x, y in enumerate('abcdefghijklmnopqrstuvwxyz')]
tree = self._makeOne(ITEMS)
self.assertEqual(list(tree.byValue(22)),
[(y, x) for x, y in reversed(ITEMS[22:])])
def testRejectDefaultComparison(self):
# Check that passing int keys w default comparison fails.
......@@ -146,9 +152,9 @@ class OOBTreePyTest(OOBTreeTest):
# default 'object' comparison semantics.
#class OOBTreePyTest(BTreeTests, unittest.TestCase):
def _makeOne(self):
def _makeOne(self, *args):
from BTrees.OOBTree import OOBTreePy
return OOBTreePy()
return OOBTreePy(*args)
......
......@@ -2334,7 +2334,7 @@ class TreeTests(unittest.TestCase):
ITEMS = [(y, x) for x, y in enumerate('abcdefghijklmnopqrstuvwxyz')]
tree = self._makeOne(ITEMS)
self.assertEqual(list(tree.byValue(min=22)),
[(y, x) for x, y in ITEMS[22:]])
[(y, x) for x, y in reversed(ITEMS[22:])])
def test_insert_new_key(self):
tree = self._makeOne()
......
``BTrees`` Changelog
====================
Unreleased
----------
- Ensure that pure-Python implementation of ``OOBTree.byValue`` matches
semantics (reversed-sort) of C implementation.
4.0.7 (2013-05-22)
------------------
......
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