summaryrefslogtreecommitdiff
path: root/Lib/bsddb/test/test_compare.py
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2010-03-22 14:22:26 +0000
committerJesus Cea <jcea@jcea.es>2010-03-22 14:22:26 +0000
commitcd0903fb98c3c7f583fecff2fd8df7fbaea905f0 (patch)
tree2f7dd5287a532bad9ce4abfede3ce8af339d9756 /Lib/bsddb/test/test_compare.py
parent6d26f3e8f70e34c770008de017d64d9a569ce307 (diff)
downloadcpython-cd0903fb98c3c7f583fecff2fd8df7fbaea905f0.tar.gz
pybsddb 4.8.4 integration. Please, comment in issue #8156
Diffstat (limited to 'Lib/bsddb/test/test_compare.py')
-rw-r--r--Lib/bsddb/test/test_compare.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/Lib/bsddb/test/test_compare.py b/Lib/bsddb/test/test_compare.py
index 4cf578b6b2..db9cd74805 100644
--- a/Lib/bsddb/test/test_compare.py
+++ b/Lib/bsddb/test/test_compare.py
@@ -12,6 +12,12 @@ from test_all import db, dbshelve, test_support, \
get_new_environment_path, get_new_database_path
+# Needed for python 3. "cmp" vanished in 3.0.1
+def cmp(a, b) :
+ if a==b : return 0
+ if a<b : return -1
+ return 1
+
lexical_cmp = cmp
def lowercase_cmp(left, right):
@@ -26,12 +32,16 @@ _expected_lexical_test_data = ['', 'CCCP', 'a', 'aaa', 'b', 'c', 'cccce', 'ccccf
_expected_lowercase_test_data = ['', 'a', 'aaa', 'b', 'c', 'CC', 'cccce', 'ccccf', 'CCCP']
class ComparatorTests (unittest.TestCase):
+ if sys.version_info < (2, 4) :
+ def assertTrue(self, expr, msg=None) :
+ return self.failUnless(expr,msg=msg)
+
def comparator_test_helper (self, comparator, expected_data):
data = expected_data[:]
import sys
- if sys.version_info[:3] < (2, 6, 0):
- if sys.version_info[:3] < (2, 4, 0):
+ if sys.version_info < (2, 6) :
+ if sys.version_info < (2, 4) :
data.sort(comparator)
else :
data.sort(cmp=comparator)
@@ -47,7 +57,7 @@ class ComparatorTests (unittest.TestCase):
data2.append(i)
data = data2
- self.assertEqual (data, expected_data,
+ self.assertEqual(data, expected_data,
"comparator `%s' is not right: %s vs. %s"
% (comparator, expected_data, data))
def test_lexical_comparator (self):
@@ -65,6 +75,15 @@ class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
env = None
db = None
+ if sys.version_info < (2, 4) :
+ def assertTrue(self, expr, msg=None):
+ self.failUnless(expr,msg=msg)
+
+ if (sys.version_info < (2, 7)) or ((sys.version_info >= (3,0)) and
+ (sys.version_info < (3, 2))) :
+ def assertLess(self, a, b, msg=None) :
+ return self.assertTrue(a<b, msg=msg)
+
def setUp (self):
self.filename = self.__class__.__name__ + '.db'
self.homeDir = get_new_environment_path()
@@ -115,14 +134,14 @@ class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
rec = curs.first ()
while rec:
key, ignore = rec
- self.assertLess (index, len (expected),
+ self.assertLess(index, len (expected),
"to many values returned from cursor")
- self.assertEqual (expected[index], key,
+ self.assertEqual(expected[index], key,
"expected value `%s' at %d but got `%s'"
% (expected[index], index, key))
index = index + 1
rec = curs.next ()
- self.assertEqual (index, len (expected),
+ self.assertEqual(index, len (expected),
"not enough values returned from cursor")
finally:
curs.close ()
@@ -193,7 +212,8 @@ class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase):
errorOut = temp.getvalue()
if not successRe.search(errorOut):
self.fail("unexpected stderr output:\n"+errorOut)
- sys.exc_traceback = sys.last_traceback = None
+ if sys.version_info < (3, 0) : # XXX: How to do this in Py3k ???
+ sys.exc_traceback = sys.last_traceback = None
def _test_compare_function_exception (self):
self.startTest ()
@@ -237,8 +257,8 @@ class BtreeExceptionsTestCase (AbstractBtreeKeyCompareTestCase):
def my_compare (a, b):
return 0
- self.startTest ()
- self.createDB (my_compare)
+ self.startTest()
+ self.createDB(my_compare)
self.assertRaises (RuntimeError, self.db.set_bt_compare, my_compare)
def test_suite ():