]> granicus.if.org Git - python/commitdiff
Fix the bsddb3 unit tests.
authorGuido van Rossum <guido@python.org>
Thu, 24 Aug 2006 18:19:44 +0000 (18:19 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 24 Aug 2006 18:19:44 +0000 (18:19 +0000)
This essentially meant fixing one case where a list of custom objects
was being sorted, and fixing one genuine bug where a method call was
missing parentheses.

Lib/bsddb/test/test_basics.py
Lib/bsddb/test/test_dbshelve.py

index 7e6ba529307e040d547ab0d1ff952bc619075ef1..e0452df92f9d2fcf67d4819d08ebbda46ee7f59c 100644 (file)
@@ -697,7 +697,7 @@ class BasicTransactionTestCase(BasicTestCase):
         for log in logs:
             if verbose:
                 print 'log file: ' + log
-        if db.version >= (4,2):
+        if db.version() >= (4,2):
             logs = self.env.log_archive(db.DB_ARCH_REMOVE)
             assert not logs
 
index 002bda910eb96046154e260b723842356036e9da..374ccd8c60f8b1c9475b846a15e4b3cb2f392ede 100644 (file)
@@ -23,11 +23,24 @@ from .test_all import verbose
 # We want the objects to be comparable so we can test dbshelve.values
 # later on.
 class DataClass:
+
     def __init__(self):
         self.value = random.random()
 
-    def __cmp__(self, other):
-        return cmp(self.value, other)
+    def __repr__(self):
+        return "DataClass(%r)" % self.value
+
+    def __eq__(self, other):
+        value = self.value
+        if isinstance(other, DataClass):
+            other = other.value
+        return value == other
+
+    def __lt__(self, other):
+        value = self.value
+        if isinstance(other, DataClass):
+            other = other.value
+        return value < other
 
 class DBShelveTestCase(unittest.TestCase):
     def setUp(self):
@@ -103,11 +116,10 @@ class DBShelveTestCase(unittest.TestCase):
                 print "%s: %s" % (key, value)
             self.checkrec(key, value)
 
-        dbvalues = d.values()
+        dbvalues = sorted(d.values(), key=lambda x: (str(type(x)), x))
         assert len(dbvalues) == len(d.keys())
-        values.sort()
-        dbvalues.sort()
-        assert values == dbvalues
+        values.sort(key=lambda x: (str(type(x)), x))
+        assert values == dbvalues, "%r != %r" % (values, dbvalues)
 
         items = d.items()
         assert len(items) == len(values)