#7092: silence py3k warnings for bsddb. Patch by Florent Xicluna.
This commit is contained in:
parent
039c899388
commit
5d62cfe070
|
@ -332,7 +332,7 @@ class bsdTableDB :
|
|||
except db.DBError, dberror:
|
||||
if txn:
|
||||
txn.abort()
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1]
|
||||
|
@ -416,7 +416,7 @@ class bsdTableDB :
|
|||
except db.DBError, dberror:
|
||||
if txn:
|
||||
txn.abort()
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1]
|
||||
|
@ -499,7 +499,7 @@ class bsdTableDB :
|
|||
if txn:
|
||||
txn.abort()
|
||||
self.db.delete(_rowid_key(table, rowid))
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1], info[2]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1], info[2]
|
||||
|
@ -554,7 +554,7 @@ class bsdTableDB :
|
|||
raise
|
||||
|
||||
except db.DBError, dberror:
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1]
|
||||
|
@ -598,7 +598,7 @@ class bsdTableDB :
|
|||
txn.abort()
|
||||
raise
|
||||
except db.DBError, dberror:
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1]
|
||||
|
@ -621,7 +621,7 @@ class bsdTableDB :
|
|||
columns = self.__tablecolumns[table]
|
||||
matching_rowids = self.__Select(table, columns, conditions)
|
||||
except db.DBError, dberror:
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
raise TableDBError, dberror[1]
|
||||
else :
|
||||
raise TableDBError, dberror.args[1]
|
||||
|
@ -677,7 +677,7 @@ class bsdTableDB :
|
|||
# leave all unknown condition callables alone as equals
|
||||
return 0
|
||||
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
conditionlist = conditions.items()
|
||||
conditionlist.sort(cmp_conditions)
|
||||
else : # Insertion Sort. Please, improve
|
||||
|
@ -745,7 +745,7 @@ class bsdTableDB :
|
|||
rowdata[column] = self.db.get(
|
||||
_data_key(table, column, rowid))
|
||||
except db.DBError, dberror:
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info < (2, 6) :
|
||||
if dberror[0] != db.DB_NOTFOUND:
|
||||
raise
|
||||
else :
|
||||
|
|
|
@ -139,11 +139,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
try:
|
||||
d.delete('abcd')
|
||||
except db.DBNotFoundError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
|
@ -162,11 +158,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
try:
|
||||
d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
|
||||
except db.DBKeyExistError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_KEYEXIST)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_KEYEXIST)
|
||||
self.assertEqual(val.args[0], db.DB_KEYEXIST)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
|
@ -301,11 +293,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
rec = c.next()
|
||||
except db.DBNotFoundError, val:
|
||||
if get_raises_error:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
if verbose: print val
|
||||
rec = None
|
||||
else:
|
||||
|
@ -326,11 +314,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
rec = c.prev()
|
||||
except db.DBNotFoundError, val:
|
||||
if get_raises_error:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
if verbose: print val
|
||||
rec = None
|
||||
else:
|
||||
|
@ -353,11 +337,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
try:
|
||||
n = c.set('bad key')
|
||||
except db.DBNotFoundError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
if verbose: print val
|
||||
else:
|
||||
if set_raises_error:
|
||||
|
@ -371,11 +351,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
try:
|
||||
n = c.get_both('0404', 'bad data')
|
||||
except db.DBNotFoundError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_NOTFOUND)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
self.assertEqual(val.args[0], db.DB_NOTFOUND)
|
||||
if verbose: print val
|
||||
else:
|
||||
if get_raises_error:
|
||||
|
@ -404,11 +380,7 @@ class BasicTestCase(unittest.TestCase):
|
|||
rec = c.current()
|
||||
except db.DBKeyEmptyError, val:
|
||||
if get_raises_error:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.DB_KEYEMPTY)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.DB_KEYEMPTY)
|
||||
self.assertEqual(val.args[0], db.DB_KEYEMPTY)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("unexpected DBKeyEmptyError")
|
||||
|
@ -451,13 +423,9 @@ class BasicTestCase(unittest.TestCase):
|
|||
print "attempting to use a closed cursor's %s method" % \
|
||||
method
|
||||
# a bug may cause a NULL pointer dereference...
|
||||
apply(getattr(c, method), args)
|
||||
getattr(c, method)(*args)
|
||||
except db.DBError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], 0)
|
||||
else :
|
||||
self.assertEqual(val.args[0], 0)
|
||||
self.assertEqual(val.args[0], 0)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("no exception raised when using a buggy cursor's"
|
||||
|
@ -710,10 +678,10 @@ class BasicTransactionTestCase(BasicTestCase):
|
|||
pass
|
||||
|
||||
statDict = self.env.log_stat(0);
|
||||
self.assert_(statDict.has_key('magic'))
|
||||
self.assert_(statDict.has_key('version'))
|
||||
self.assert_(statDict.has_key('cur_file'))
|
||||
self.assert_(statDict.has_key('region_nowait'))
|
||||
self.assertIn('magic', statDict)
|
||||
self.assertIn('version', statDict)
|
||||
self.assertIn('cur_file', statDict)
|
||||
self.assertIn('region_nowait', statDict)
|
||||
|
||||
# must have at least one log file present:
|
||||
logs = self.env.log_archive(db.DB_ARCH_ABS | db.DB_ARCH_LOG)
|
||||
|
|
|
@ -30,7 +30,7 @@ class ComparatorTests (unittest.TestCase):
|
|||
data = expected_data[:]
|
||||
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
if sys.version_info[:3] < (2, 6, 0):
|
||||
if sys.version_info[:3] < (2, 4, 0):
|
||||
data.sort(comparator)
|
||||
else :
|
||||
|
@ -47,7 +47,7 @@ class ComparatorTests (unittest.TestCase):
|
|||
data2.append(i)
|
||||
data = data2
|
||||
|
||||
self.failUnless (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):
|
||||
|
@ -115,14 +115,14 @@ class AbstractBtreeKeyCompareTestCase (unittest.TestCase):
|
|||
rec = curs.first ()
|
||||
while rec:
|
||||
key, ignore = rec
|
||||
self.failUnless (index < len (expected),
|
||||
self.assertLess (index, len (expected),
|
||||
"to many values returned from cursor")
|
||||
self.failUnless (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.failUnless (index == len (expected),
|
||||
self.assertEqual (index, len (expected),
|
||||
"not enough values returned from cursor")
|
||||
finally:
|
||||
curs.close ()
|
||||
|
|
|
@ -27,7 +27,7 @@ class dbobjTestCase(unittest.TestCase):
|
|||
def put(self, key, *args, **kwargs):
|
||||
key = key.upper()
|
||||
# call our parent classes put method with an upper case key
|
||||
return apply(dbobj.DB.put, (self, key) + args, kwargs)
|
||||
return dbobj.DB.put(self, key, *args, **kwargs)
|
||||
self.env = TestDBEnv()
|
||||
self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
|
||||
self.db = TestDB(self.env)
|
||||
|
|
|
@ -5,6 +5,7 @@ TestCases for checking dbShelve objects.
|
|||
import os, string
|
||||
import random
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
|
||||
from test_all import db, dbshelve, test_support, verbose, \
|
||||
|
@ -117,15 +118,11 @@ class DBShelveTestCase(unittest.TestCase):
|
|||
|
||||
dbvalues = d.values()
|
||||
self.assertEqual(len(dbvalues), len(d.keys()))
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
values.sort()
|
||||
dbvalues.sort()
|
||||
self.assertEqual(values, dbvalues)
|
||||
else : # XXX: Convert all to strings. Please, improve
|
||||
values.sort(key=lambda x : str(x))
|
||||
dbvalues.sort(key=lambda x : str(x))
|
||||
self.assertEqual(repr(values), repr(dbvalues))
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('ignore',
|
||||
'comparing unequal types not supported',
|
||||
DeprecationWarning)
|
||||
self.assertEqual(sorted(values), sorted(dbvalues))
|
||||
|
||||
items = d.items()
|
||||
self.assertEqual(len(items), len(values))
|
||||
|
|
|
@ -51,13 +51,13 @@ class JoinTestCase(unittest.TestCase):
|
|||
# create and populate primary index
|
||||
priDB = db.DB(self.env)
|
||||
priDB.open(self.filename, "primary", db.DB_BTREE, db.DB_CREATE)
|
||||
map(lambda t, priDB=priDB: apply(priDB.put, t), ProductIndex)
|
||||
map(lambda t, priDB=priDB: priDB.put(*t), ProductIndex)
|
||||
|
||||
# create and populate secondary index
|
||||
secDB = db.DB(self.env)
|
||||
secDB.set_flags(db.DB_DUP | db.DB_DUPSORT)
|
||||
secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE)
|
||||
map(lambda t, secDB=secDB: apply(secDB.put, t), ColorIndex)
|
||||
map(lambda t, secDB=secDB: secDB.put(*t), ColorIndex)
|
||||
|
||||
sCursor = None
|
||||
jCursor = None
|
||||
|
|
|
@ -60,11 +60,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
|
|||
try:
|
||||
data = d[0] # This should raise a KeyError!?!?!
|
||||
except db.DBInvalidArgError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.EINVAL)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.EINVAL)
|
||||
self.assertEqual(val.args[0], db.EINVAL)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
|
@ -269,11 +265,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
|
|||
try: # this one will fail
|
||||
d.append('bad' * 20)
|
||||
except db.DBInvalidArgError, val:
|
||||
import sys
|
||||
if sys.version_info[0] < 3 :
|
||||
self.assertEqual(val[0], db.EINVAL)
|
||||
else :
|
||||
self.assertEqual(val.args[0], db.EINVAL)
|
||||
self.assertEqual(val.args[0], db.EINVAL)
|
||||
if verbose: print val
|
||||
else:
|
||||
self.fail("expected exception")
|
||||
|
|
|
@ -12,6 +12,8 @@ from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
|
|||
|
||||
# Skip test if _bsddb module was not built.
|
||||
import_module('_bsddb')
|
||||
# Silence Py3k warning
|
||||
import_module('bsddb', deprecated=True)
|
||||
|
||||
# When running as a script instead of within the regrtest framework, skip the
|
||||
# requires test, since it's obvious we want to run them.
|
||||
|
|
Loading…
Reference in New Issue