summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-01-30 02:55:10 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-01-30 02:55:10 (GMT)
commitd4cb56d4e88c7e001bbaba2c80953db47632f199 (patch)
tree73c95e0223ed8a98fac797fc99ab1bffae9c5457 /Lib/bsddb/test
parentfd66e51c4c1ff9293b0f332d6ebc8093b2ef12bb (diff)
downloadcpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.zip
cpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.tar.gz
cpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.tar.bz2
Convert some custom sort comparison functions to equivalent key functions.
Diffstat (limited to 'Lib/bsddb/test')
-rw-r--r--Lib/bsddb/test/test_compare.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/bsddb/test/test_compare.py b/Lib/bsddb/test/test_compare.py
index a36faae..49aa7ca 100644
--- a/Lib/bsddb/test/test_compare.py
+++ b/Lib/bsddb/test/test_compare.py
@@ -32,10 +32,20 @@ _expected_lexical_test_data = [s.encode('ascii') for s in
_expected_lowercase_test_data = [s.encode('ascii') for s in
('', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf', 'CCCP')]
+
+def CmpToKey(mycmp):
+ 'Convert a cmp= function into a key= function'
+ class K(object):
+ def __init__(self, obj, *args):
+ self.obj = obj
+ def __lt__(self, other):
+ return mycmp(self.obj, other.obj) == -1
+ return K
+
class ComparatorTests (unittest.TestCase):
def comparator_test_helper (self, comparator, expected_data):
data = expected_data[:]
- data.sort (comparator)
+ data.sort (key=CmpToKey(comparator))
self.failUnless (data == expected_data,
"comparator `%s' is not right: %s vs. %s"
% (comparator, expected_data, data))