summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/dbtables.py4
-rw-r--r--Lib/bsddb/test/test_all.py18
-rw-r--r--Lib/bsddb/test/test_associate.py36
-rw-r--r--Lib/bsddb/test/test_basics.py148
-rw-r--r--Lib/bsddb/test/test_compat.py30
-rw-r--r--Lib/bsddb/test/test_dbshelve.py20
-rw-r--r--Lib/bsddb/test/test_dbtables.py8
-rw-r--r--Lib/bsddb/test/test_join.py6
-rw-r--r--Lib/bsddb/test/test_lock.py20
-rw-r--r--Lib/bsddb/test/test_queue.py34
-rw-r--r--Lib/bsddb/test/test_recno.py42
-rw-r--r--Lib/bsddb/test/test_thread.py72
12 files changed, 219 insertions, 219 deletions
diff --git a/Lib/bsddb/dbtables.py b/Lib/bsddb/dbtables.py
index 704c4d2..5359de8 100644
--- a/Lib/bsddb/dbtables.py
+++ b/Lib/bsddb/dbtables.py
@@ -208,12 +208,12 @@ class bsdTableDB :
def _db_print(self) :
"""Print the database to stdout for debugging"""
- print "******** Printing raw database for debugging ********"
+ print("******** Printing raw database for debugging ********")
cur = self.db.cursor()
try:
key, data = cur.first()
while 1:
- print repr({key: data})
+ print(repr({key: data}))
next = cur.next()
if next:
key, data = next
diff --git a/Lib/bsddb/test/test_all.py b/Lib/bsddb/test/test_all.py
index 0b132f4..b3ef5b9 100644
--- a/Lib/bsddb/test/test_all.py
+++ b/Lib/bsddb/test/test_all.py
@@ -22,15 +22,15 @@ if 'silent' in sys.argv: # take care of old flag, just in case
def print_versions():
- print
- print '-=' * 38
- print db.DB_VERSION_STRING
- print 'bsddb.db.version(): %s' % (db.version(), )
- print 'bsddb.db.__version__: %s' % db.__version__
- print 'bsddb.db.cvsid: %s' % db.cvsid
- print 'python version: %s' % sys.version
- print 'My pid: %s' % os.getpid()
- print '-=' * 38
+ print()
+ print('-=' * 38)
+ print(db.DB_VERSION_STRING)
+ print('bsddb.db.version(): %s' % (db.version(), ))
+ print('bsddb.db.__version__: %s' % db.__version__)
+ print('bsddb.db.cvsid: %s' % db.cvsid)
+ print('python version: %s' % sys.version)
+ print('My pid: %s' % os.getpid())
+ print('-=' * 38)
class PrintInfoFakeTest(unittest.TestCase):
diff --git a/Lib/bsddb/test/test_associate.py b/Lib/bsddb/test/test_associate.py
index 7ae7c53..857cd3d 100644
--- a/Lib/bsddb/test/test_associate.py
+++ b/Lib/bsddb/test/test_associate.py
@@ -114,9 +114,9 @@ class AssociateErrorTestCase(unittest.TestCase):
def test00_associateDBError(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test00_associateDBError..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test00_associateDBError..." % \
+ self.__class__.__name__)
dupDB = db.DB(self.env)
dupDB.set_flags(db.DB_DUP)
@@ -207,9 +207,9 @@ class AssociateTestCase(unittest.TestCase):
def test01_associateWithDB(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_associateWithDB..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_associateWithDB..." % \
+ self.__class__.__name__)
self.createDB()
@@ -227,9 +227,9 @@ class AssociateTestCase(unittest.TestCase):
def test02_associateAfterDB(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_associateAfterDB..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_associateAfterDB..." % \
+ self.__class__.__name__)
self.createDB()
self.addDataToDB(self.getDB())
@@ -257,7 +257,7 @@ class AssociateTestCase(unittest.TestCase):
vals[1].index('unknown')
if verbose:
- print "Primary key traversal:"
+ print("Primary key traversal:")
self.cur = self.getDB().cursor(txn)
count = 0
rec = self.cur.first()
@@ -268,13 +268,13 @@ class AssociateTestCase(unittest.TestCase):
assert rec[0] and type(rec[0]) == type(0)
count = count + 1
if verbose:
- print rec
+ print(rec)
rec = self.cur.next()
assert count == len(musicdata) # all items accounted for
if verbose:
- print "Secondary key traversal:"
+ print("Secondary key traversal:")
self.cur = secDB.cursor(txn)
count = 0
@@ -294,7 +294,7 @@ class AssociateTestCase(unittest.TestCase):
while rec is not None:
count = count + 1
if verbose:
- print rec
+ print(rec)
rec = self.cur.next()
# all items accounted for EXCEPT for 1 with "Blues" genre
assert count == len(musicdata)-1
@@ -304,7 +304,7 @@ class AssociateTestCase(unittest.TestCase):
def getGenre(self, priKey, priData):
assert type(priData) == type("")
if verbose:
- print 'getGenre key: %r data: %r' % (priKey, priData)
+ print('getGenre key: %r data: %r' % (priKey, priData))
genre = string.split(priData, '|')[2]
if genre == 'Blues':
return db.DB_DONOTINDEX
@@ -343,9 +343,9 @@ class AssociateBTreeTxnTestCase(AssociateBTreeTestCase):
def test13_associate_in_transaction(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test13_associateAutoCommit..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test13_associateAutoCommit..." % \
+ self.__class__.__name__)
txn = self.env.txn_begin()
try:
@@ -389,7 +389,7 @@ class ShelveAssociateTestCase(AssociateTestCase):
def getGenre(self, priKey, priData):
assert type(priData) == type(())
if verbose:
- print 'getGenre key: %r data: %r' % (priKey, priData)
+ print('getGenre key: %r data: %r' % (priKey, priData))
genre = priData[2]
if genre == 'Blues':
return db.DB_DONOTINDEX
diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py
index 281e942..a9d7be0 100644
--- a/Lib/bsddb/test/test_basics.py
+++ b/Lib/bsddb/test/test_basics.py
@@ -31,10 +31,10 @@ class VersionTestCase(unittest.TestCase):
def test00_version(self):
info = db.version()
if verbose:
- print '\n', '-=' * 20
- print 'bsddb.db.version(): %s' % (info, )
- print db.DB_VERSION_STRING
- print '-=' * 20
+ print('\n', '-=' * 20)
+ print('bsddb.db.version(): %s' % (info, ))
+ print(db.DB_VERSION_STRING)
+ print('-=' * 20)
assert info == (db.DB_VERSION_MAJOR, db.DB_VERSION_MINOR,
db.DB_VERSION_PATCH)
@@ -131,7 +131,7 @@ class BasicTestCase(unittest.TestCase):
num = len(d)
if verbose:
- print "created %d records" % num
+ print("created %d records" % num)
def makeData(self, key):
@@ -145,13 +145,13 @@ class BasicTestCase(unittest.TestCase):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_GetsAndPuts..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_GetsAndPuts..." % self.__class__.__name__)
for key in ['0001', '0100', '0400', '0700', '0999']:
data = d.get(key)
if verbose:
- print data
+ print(data)
assert d.get('0321') == '0321-0321-0321-0321-0321'
@@ -164,7 +164,7 @@ class BasicTestCase(unittest.TestCase):
d.delete('abcd')
except db.DBNotFoundError as val:
assert val[0] == db.DB_NOTFOUND
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("expected exception")
@@ -183,7 +183,7 @@ class BasicTestCase(unittest.TestCase):
d.put('abcd', 'this should fail', flags=db.DB_NOOVERWRITE)
except db.DBKeyExistError as val:
assert val[0] == db.DB_KEYEXIST
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("expected exception")
@@ -212,7 +212,7 @@ class BasicTestCase(unittest.TestCase):
rec = d.get_both('0555', '0555-0555-0555-0555-0555')
if verbose:
- print rec
+ print(rec)
assert d.get_both('0555', 'bad data') == None
@@ -227,7 +227,7 @@ class BasicTestCase(unittest.TestCase):
s = d.stat()
assert type(s) == type({})
if verbose:
- print 'd.stat() returned this dictionary:'
+ print('d.stat() returned this dictionary:')
pprint(s)
@@ -237,15 +237,15 @@ class BasicTestCase(unittest.TestCase):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_DictionaryMethods..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_DictionaryMethods..." % \
+ self.__class__.__name__)
for key in ['0002', '0101', '0401', '0701', '0998']:
data = d[key]
assert data == self.makeData(key)
if verbose:
- print data
+ print(data)
assert len(d) == self._numKeys
keys = d.keys()
@@ -263,7 +263,7 @@ class BasicTestCase(unittest.TestCase):
assert len(keys) == self._numKeys+1
if verbose:
- print "the first 10 keys are:"
+ print("the first 10 keys are:")
pprint(keys[:10])
assert d['new record'] == 'a replacement record'
@@ -278,7 +278,7 @@ class BasicTestCase(unittest.TestCase):
assert len(items[0]) == 2
if verbose:
- print "the first 10 items are:"
+ print("the first 10 items are:")
pprint(items[:10])
values = d.values()
@@ -286,7 +286,7 @@ class BasicTestCase(unittest.TestCase):
assert type(values) == type([])
if verbose:
- print "the first 10 values are:"
+ print("the first 10 values are:")
pprint(values[:10])
@@ -295,9 +295,9 @@ class BasicTestCase(unittest.TestCase):
def test03_SimpleCursorStuff(self, get_raises_error=0, set_raises_error=0):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test03_SimpleCursorStuff (get_error %s, set_error %s)..." % \
- (self.__class__.__name__, get_raises_error, set_raises_error)
+ print('\n', '-=' * 30)
+ print("Running %s.test03_SimpleCursorStuff (get_error %s, set_error %s)..." % \
+ (self.__class__.__name__, get_raises_error, set_raises_error))
if self.env and self.dbopenflags & db.DB_AUTO_COMMIT:
txn = self.env.txn_begin()
@@ -310,13 +310,13 @@ class BasicTestCase(unittest.TestCase):
while rec is not None:
count = count + 1
if verbose and count % 100 == 0:
- print rec
+ print(rec)
try:
rec = c.next()
except db.DBNotFoundError as val:
if get_raises_error:
assert val[0] == db.DB_NOTFOUND
- if verbose: print val
+ if verbose: print(val)
rec = None
else:
self.fail("unexpected DBNotFoundError")
@@ -330,13 +330,13 @@ class BasicTestCase(unittest.TestCase):
while rec is not None:
count = count + 1
if verbose and count % 100 == 0:
- print rec
+ print(rec)
try:
rec = c.prev()
except db.DBNotFoundError as val:
if get_raises_error:
assert val[0] == db.DB_NOTFOUND
- if verbose: print val
+ if verbose: print(val)
rec = None
else:
self.fail("unexpected DBNotFoundError")
@@ -359,7 +359,7 @@ class BasicTestCase(unittest.TestCase):
n = c.set('bad key')
except db.DBNotFoundError as val:
assert val[0] == db.DB_NOTFOUND
- if verbose: print val
+ if verbose: print(val)
else:
if set_raises_error:
self.fail("expected exception")
@@ -373,7 +373,7 @@ class BasicTestCase(unittest.TestCase):
n = c.get_both('0404', 'bad data')
except db.DBNotFoundError as val:
assert val[0] == db.DB_NOTFOUND
- if verbose: print val
+ if verbose: print(val)
else:
if get_raises_error:
self.fail("expected exception")
@@ -383,16 +383,16 @@ class BasicTestCase(unittest.TestCase):
if self.d.get_type() == db.DB_BTREE:
rec = c.set_range('011')
if verbose:
- print "searched for '011', found: ", rec
+ print("searched for '011', found: ", rec)
rec = c.set_range('011',dlen=0,doff=0)
if verbose:
- print "searched (partial) for '011', found: ", rec
+ print("searched (partial) for '011', found: ", rec)
if rec[1] != '': self.fail('expected empty data portion')
ev = c.set_range('empty value')
if verbose:
- print "search for 'empty value' returned", ev
+ print("search for 'empty value' returned", ev)
if ev[1] != '': self.fail('empty value lookup failed')
c.set('0499')
@@ -402,7 +402,7 @@ class BasicTestCase(unittest.TestCase):
except db.DBKeyEmptyError as val:
if get_raises_error:
assert val[0] == db.DB_KEYEMPTY
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("unexpected DBKeyEmptyError")
else:
@@ -441,13 +441,13 @@ class BasicTestCase(unittest.TestCase):
for method, args in methods_to_test.items():
try:
if verbose:
- print "attempting to use a closed cursor's %s method" % \
- method
+ print("attempting to use a closed cursor's %s method" % \
+ method)
# a bug may cause a NULL pointer dereference...
getattr(c, method)(*args)
except db.DBError as val:
assert val[0] == 0
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("no exception raised when using a buggy cursor's"
"%s method" % method)
@@ -466,9 +466,9 @@ class BasicTestCase(unittest.TestCase):
def test03b_SimpleCursorWithoutGetReturnsNone0(self):
# same test but raise exceptions instead of returning None
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \
+ self.__class__.__name__)
old = self.d.set_get_returns_none(0)
assert old == 2
@@ -477,9 +477,9 @@ class BasicTestCase(unittest.TestCase):
def test03b_SimpleCursorWithGetReturnsNone1(self):
# same test but raise exceptions instead of returning None
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test03b_SimpleCursorStuffWithoutGetReturnsNone..." % \
+ self.__class__.__name__)
old = self.d.set_get_returns_none(1)
self.test03_SimpleCursorStuff(get_raises_error=0, set_raises_error=1)
@@ -488,9 +488,9 @@ class BasicTestCase(unittest.TestCase):
def test03c_SimpleCursorGetReturnsNone2(self):
# same test but raise exceptions instead of returning None
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test03c_SimpleCursorStuffWithoutSetReturnsNone..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test03c_SimpleCursorStuffWithoutSetReturnsNone..." % \
+ self.__class__.__name__)
old = self.d.set_get_returns_none(1)
assert old == 2
@@ -503,9 +503,9 @@ class BasicTestCase(unittest.TestCase):
def test04_PartialGetAndPut(self):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test04_PartialGetAndPut..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test04_PartialGetAndPut..." % \
+ self.__class__.__name__)
key = "partialTest"
data = "1" * 1000 + "2" * 1000
@@ -533,8 +533,8 @@ class BasicTestCase(unittest.TestCase):
def test05_GetSize(self):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test05_GetSize..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test05_GetSize..." % self.__class__.__name__)
for i in range(1, 50000, 500):
key = "size%s" % i
@@ -553,8 +553,8 @@ class BasicTestCase(unittest.TestCase):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test99_Truncate..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test99_Truncate..." % self.__class__.__name__)
d.put("abcde", "ABCDE");
num = d.truncate()
@@ -598,8 +598,8 @@ class BasicWithEnvTestCase(BasicTestCase):
return
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test07_EnvRemoveAndRename..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test07_EnvRemoveAndRename..." % self.__class__.__name__)
# can't rename or remove an open DB
self.d.close()
@@ -647,8 +647,8 @@ class BasicTransactionTestCase(BasicTestCase):
def test06_Transactions(self):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test06_Transactions..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test06_Transactions..." % self.__class__.__name__)
assert d.get('new rec', txn=self.txn) == None
d.put('new rec', 'this is a new record', self.txn)
@@ -671,7 +671,7 @@ class BasicTransactionTestCase(BasicTestCase):
while rec is not None:
count = count + 1
if verbose and count % 100 == 0:
- print rec
+ print(rec)
rec = c.next()
assert count == self._numKeys+1
@@ -696,7 +696,7 @@ class BasicTransactionTestCase(BasicTestCase):
assert logs != None
for log in logs:
if verbose:
- print 'log file: ' + log
+ print('log file: ' + log)
if db.version() >= (4,2):
logs = self.env.log_archive(db.DB_ARCH_REMOVE)
assert not logs
@@ -712,8 +712,8 @@ class BasicTransactionTestCase(BasicTestCase):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test07_TxnTruncate..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test07_TxnTruncate..." % self.__class__.__name__)
d.put("abcde", "ABCDE");
txn = self.env.txn_begin()
@@ -762,21 +762,21 @@ class BTreeRecnoTestCase(BasicTestCase):
def test07_RecnoInBTree(self):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test07_RecnoInBTree..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test07_RecnoInBTree..." % self.__class__.__name__)
rec = d.get(200)
assert type(rec) == type(())
assert len(rec) == 2
if verbose:
- print "Record #200 is ", rec
+ print("Record #200 is ", rec)
c = d.cursor()
c.set('0200')
num = c.get_recno()
assert type(num) == type(1)
if verbose:
- print "recno of d['0200'] is ", num
+ print("recno of d['0200'] is ", num)
rec = c.current()
assert c.set_recno(num) == rec
@@ -796,9 +796,9 @@ class BasicDUPTestCase(BasicTestCase):
def test08_DuplicateKeys(self):
d = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test08_DuplicateKeys..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test08_DuplicateKeys..." % \
+ self.__class__.__name__)
d.put("dup0", "before")
for x in "The quick brown fox jumped over the lazy dog.".split():
@@ -808,7 +808,7 @@ class BasicDUPTestCase(BasicTestCase):
data = d.get("dup1")
assert data == "The"
if verbose:
- print data
+ print(data)
c = d.cursor()
rec = c.set("dup1")
@@ -827,14 +827,14 @@ class BasicDUPTestCase(BasicTestCase):
rec = c.set('dup1')
while rec is not None:
if verbose:
- print rec
+ print(rec)
rec = c.next_dup()
c.set('dup1')
rec = c.next_nodup()
assert rec[0] != 'dup1'
if verbose:
- print rec
+ print(rec)
c.close()
@@ -869,8 +869,8 @@ class BasicMultiDBTestCase(BasicTestCase):
def test09_MultiDB(self):
d1 = self.d
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test09_MultiDB..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test09_MultiDB..." % self.__class__.__name__)
d2 = db.DB(self.env)
d2.open(self.filename, "second", self.dbtype,
@@ -910,7 +910,7 @@ class BasicMultiDBTestCase(BasicTestCase):
while rec is not None:
count = count + 1
if verbose and (count % 50) == 0:
- print rec
+ print(rec)
rec = c1.next()
assert count == self._numKeys
@@ -919,7 +919,7 @@ class BasicMultiDBTestCase(BasicTestCase):
while rec is not None:
count = count + 1
if verbose:
- print rec
+ print(rec)
rec = c2.next()
assert count == 9
@@ -928,7 +928,7 @@ class BasicMultiDBTestCase(BasicTestCase):
while rec is not None:
count = count + 1
if verbose:
- print rec
+ print(rec)
rec = c3.next()
assert count == 52
diff --git a/Lib/bsddb/test/test_compat.py b/Lib/bsddb/test/test_compat.py
index af9e128..7561f9f 100644
--- a/Lib/bsddb/test/test_compat.py
+++ b/Lib/bsddb/test/test_compat.py
@@ -37,7 +37,7 @@ class CompatibilityTestCase(unittest.TestCase):
def test03_rnopen(self):
data = string.split("The quick brown fox jumped over the lazy dog.")
if verbose:
- print "\nTesting: rnopen"
+ print("\nTesting: rnopen")
f = rnopen(self.filename, 'c')
for x in range(len(data)):
@@ -45,7 +45,7 @@ class CompatibilityTestCase(unittest.TestCase):
getTest = (f[1], f[2], f[3])
if verbose:
- print '%s %s %s' % getTest
+ print('%s %s %s' % getTest)
assert getTest[1] == 'quick', 'data mismatch!'
@@ -73,7 +73,7 @@ class CompatibilityTestCase(unittest.TestCase):
rec = f.first()
while rec:
if verbose:
- print rec
+ print(rec)
try:
rec = f.next()
except KeyError:
@@ -89,17 +89,17 @@ class CompatibilityTestCase(unittest.TestCase):
def do_bthash_test(self, factory, what):
if verbose:
- print '\nTesting: ', what
+ print('\nTesting: ', what)
f = factory(self.filename, 'c')
if verbose:
- print 'creation...'
+ print('creation...')
# truth test
if f:
- if verbose: print "truth test: true"
+ if verbose: print("truth test: true")
else:
- if verbose: print "truth test: false"
+ if verbose: print("truth test: false")
f['0'] = ''
f['a'] = 'Guido'
@@ -109,10 +109,10 @@ class CompatibilityTestCase(unittest.TestCase):
# 'e' intentionally left out
f['f'] = 'Python'
if verbose:
- print '%s %s %s' % (f['a'], f['b'], f['c'])
+ print('%s %s %s' % (f['a'], f['b'], f['c']))
if verbose:
- print 'key ordering...'
+ print('key ordering...')
start = f.set_location(f.first()[0])
if start != ('0', ''):
self.fail("incorrect first() result: "+repr(start))
@@ -124,7 +124,7 @@ class CompatibilityTestCase(unittest.TestCase):
f.previous()
break
if verbose:
- print rec
+ print(rec)
assert f.has_key('f'), 'Error, missing key!'
@@ -147,9 +147,9 @@ class CompatibilityTestCase(unittest.TestCase):
# truth test
try:
if f:
- if verbose: print "truth test: true"
+ if verbose: print("truth test: true")
else:
- if verbose: print "truth test: false"
+ if verbose: print("truth test: false")
except db.DBError:
pass
else:
@@ -158,16 +158,16 @@ class CompatibilityTestCase(unittest.TestCase):
del f
if verbose:
- print 'modification...'
+ print('modification...')
f = factory(self.filename, 'w')
f['d'] = 'discovered'
if verbose:
- print 'access...'
+ print('access...')
for key in f.keys():
word = f[key]
if verbose:
- print word
+ print(word)
def noRec(f):
rec = f['no such key']
diff --git a/Lib/bsddb/test/test_dbshelve.py b/Lib/bsddb/test/test_dbshelve.py
index 1da6546..e75e9c8 100644
--- a/Lib/bsddb/test/test_dbshelve.py
+++ b/Lib/bsddb/test/test_dbshelve.py
@@ -79,8 +79,8 @@ class DBShelveTestCase(unittest.TestCase):
def test01_basics(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_basics..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_basics..." % self.__class__.__name__)
self.populateDB(self.d)
self.d.sync()
@@ -94,9 +94,9 @@ class DBShelveTestCase(unittest.TestCase):
f = d.fd()
if verbose:
- print "length:", l
- print "keys:", k
- print "stats:", s
+ print("length:", l)
+ print("keys:", k)
+ print("stats:", s)
assert 0 == d.has_key('bad key')
assert 1 == d.has_key('IA')
@@ -113,7 +113,7 @@ class DBShelveTestCase(unittest.TestCase):
value = d[key]
values.append(value)
if verbose:
- print "%s: %s" % (key, value)
+ print("%s: %s" % (key, value))
self.checkrec(key, value)
dbvalues = sorted(d.values(), key=lambda x: (str(type(x)), x))
@@ -144,8 +144,8 @@ class DBShelveTestCase(unittest.TestCase):
def test02_cursors(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_cursors..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_cursors..." % self.__class__.__name__)
self.populateDB(self.d)
d = self.d
@@ -156,7 +156,7 @@ class DBShelveTestCase(unittest.TestCase):
while rec is not None:
count = count + 1
if verbose:
- print rec
+ print(rec)
key, value = rec
self.checkrec(key, value)
rec = c.next()
@@ -170,7 +170,7 @@ class DBShelveTestCase(unittest.TestCase):
while rec is not None:
count = count + 1
if verbose:
- print rec
+ print(rec)
key, value = rec
self.checkrec(key, value)
rec = c.prev()
diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py
index a31fcec..c476e55 100644
--- a/Lib/bsddb/test/test_dbtables.py
+++ b/Lib/bsddb/test/test_dbtables.py
@@ -110,7 +110,7 @@ class TableDBTestCase(unittest.TestCase):
assert values[1]['Species'] == 'Penguin'
else :
if verbose:
- print "values= %r" % (values,)
+ print("values= %r" % (values,))
raise "Wrong values returned!"
def test03(self):
@@ -120,15 +120,15 @@ class TableDBTestCase(unittest.TestCase):
except dbtables.TableDBError:
pass
if verbose:
- print '...before CreateTable...'
+ print('...before CreateTable...')
self.tdb._db_print()
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e'])
if verbose:
- print '...after CreateTable...'
+ print('...after CreateTable...')
self.tdb._db_print()
self.tdb.Drop(tabname)
if verbose:
- print '...after Drop...'
+ print('...after Drop...')
self.tdb._db_print()
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e'])
diff --git a/Lib/bsddb/test/test_join.py b/Lib/bsddb/test/test_join.py
index 5e307ae..67507ea 100644
--- a/Lib/bsddb/test/test_join.py
+++ b/Lib/bsddb/test/test_join.py
@@ -65,9 +65,9 @@ class JoinTestCase(unittest.TestCase):
def test01_join(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_join..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_join..." % \
+ self.__class__.__name__)
# create and populate primary index
priDB = db.DB(self.env)
diff --git a/Lib/bsddb/test/test_lock.py b/Lib/bsddb/test/test_lock.py
index 61bdae8..e44bf21 100644
--- a/Lib/bsddb/test/test_lock.py
+++ b/Lib/bsddb/test/test_lock.py
@@ -49,27 +49,27 @@ class LockingTestCase(unittest.TestCase):
def test01_simple(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_simple..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_simple..." % self.__class__.__name__)
anID = self.env.lock_id()
if verbose:
- print "locker ID: %s" % anID
+ print("locker ID: %s" % anID)
lock = self.env.lock_get(anID, "some locked thing", db.DB_LOCK_WRITE)
if verbose:
- print "Aquired lock: %s" % lock
+ print("Aquired lock: %s" % lock)
time.sleep(1)
self.env.lock_put(lock)
if verbose:
- print "Released lock: %s" % lock
+ print("Released lock: %s" % lock)
def test02_threaded(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_threaded..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_threaded..." % self.__class__.__name__)
threads = []
threads.append(Thread(target = self.theThread,
@@ -113,17 +113,17 @@ class LockingTestCase(unittest.TestCase):
anID = self.env.lock_id()
if verbose:
- print "%s: locker ID: %s" % (name, anID)
+ print("%s: locker ID: %s" % (name, anID))
lock = self.env.lock_get(anID, "some locked thing", lockType)
if verbose:
- print "%s: Aquired %s lock: %s" % (name, lt, lock)
+ print("%s: Aquired %s lock: %s" % (name, lt, lock))
time.sleep(sleepTime)
self.env.lock_put(lock)
if verbose:
- print "%s: Released %s lock: %s" % (name, lt, lock)
+ print("%s: Released %s lock: %s" % (name, lt, lock))
#----------------------------------------------------------------------
diff --git a/Lib/bsddb/test/test_queue.py b/Lib/bsddb/test/test_queue.py
index 4226c9e..9f80b43 100644
--- a/Lib/bsddb/test/test_queue.py
+++ b/Lib/bsddb/test/test_queue.py
@@ -34,15 +34,15 @@ class SimpleQueueTestCase(unittest.TestCase):
# Basic Queue tests using the deprecated DBCursor.consume method.
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_basic..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_basic..." % self.__class__.__name__)
d = db.DB()
d.set_re_len(40) # Queues must be fixed length
d.open(self.filename, db.DB_QUEUE, db.DB_CREATE)
if verbose:
- print "before appends" + '-' * 30
+ print("before appends" + '-' * 30)
pprint(d.stat())
for x in string.letters:
@@ -58,7 +58,7 @@ class SimpleQueueTestCase(unittest.TestCase):
assert len(d) == 55
if verbose:
- print "before close" + '-' * 30
+ print("before close" + '-' * 30)
pprint(d.stat())
d.close()
@@ -67,25 +67,25 @@ class SimpleQueueTestCase(unittest.TestCase):
d.open(self.filename)
if verbose:
- print "after open" + '-' * 30
+ print("after open" + '-' * 30)
pprint(d.stat())
d.append("one more")
c = d.cursor()
if verbose:
- print "after append" + '-' * 30
+ print("after append" + '-' * 30)
pprint(d.stat())
rec = c.consume()
while rec:
if verbose:
- print rec
+ print(rec)
rec = c.consume()
c.close()
if verbose:
- print "after consume loop" + '-' * 30
+ print("after consume loop" + '-' * 30)
pprint(d.stat())
assert len(d) == 0, \
@@ -101,12 +101,12 @@ class SimpleQueueTestCase(unittest.TestCase):
# (No cursor needed)
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_basicPost32..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_basicPost32..." % self.__class__.__name__)
if db.version() < (3, 2, 0):
if verbose:
- print "Test not run, DB not new enough..."
+ print("Test not run, DB not new enough...")
return
d = db.DB()
@@ -114,7 +114,7 @@ class SimpleQueueTestCase(unittest.TestCase):
d.open(self.filename, db.DB_QUEUE, db.DB_CREATE)
if verbose:
- print "before appends" + '-' * 30
+ print("before appends" + '-' * 30)
pprint(d.stat())
for x in string.letters:
@@ -130,7 +130,7 @@ class SimpleQueueTestCase(unittest.TestCase):
assert len(d) == 55
if verbose:
- print "before close" + '-' * 30
+ print("before close" + '-' * 30)
pprint(d.stat())
d.close()
@@ -140,23 +140,23 @@ class SimpleQueueTestCase(unittest.TestCase):
#d.set_get_returns_none(true)
if verbose:
- print "after open" + '-' * 30
+ print("after open" + '-' * 30)
pprint(d.stat())
d.append("one more")
if verbose:
- print "after append" + '-' * 30
+ print("after append" + '-' * 30)
pprint(d.stat())
rec = d.consume()
while rec:
if verbose:
- print rec
+ print(rec)
rec = d.consume()
if verbose:
- print "after consume loop" + '-' * 30
+ print("after consume loop" + '-' * 30)
pprint(d.stat())
d.close()
diff --git a/Lib/bsddb/test/test_recno.py b/Lib/bsddb/test/test_recno.py
index 7bf3695..8baf843 100644
--- a/Lib/bsddb/test/test_recno.py
+++ b/Lib/bsddb/test/test_recno.py
@@ -45,9 +45,9 @@ class SimpleRecnoTestCase(unittest.TestCase):
assert type(recno) == type(0)
assert recno >= 1
if verbose:
- print recno,
+ print(recno, end=' ')
- if verbose: print
+ if verbose: print()
stat = d.stat()
if verbose:
@@ -56,7 +56,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
for recno in range(1, len(d)+1):
data = d[recno]
if verbose:
- print data
+ print(data)
assert type(data) == type("")
assert data == d.get(recno)
@@ -65,7 +65,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
data = d[0] # This should raise a KeyError!?!?!
except db.DBInvalidArgError as val:
assert val[0] == db.EINVAL
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("expected exception")
@@ -94,7 +94,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
keys = d.keys()
if verbose:
- print keys
+ print(keys)
assert type(keys) == type([])
assert type(keys[0]) == type(123)
assert len(keys) == len(d)
@@ -120,23 +120,23 @@ class SimpleRecnoTestCase(unittest.TestCase):
data = d.get_both(26, "z" * 60)
assert data == "z" * 60
if verbose:
- print data
+ print(data)
fd = d.fd()
if verbose:
- print fd
+ print(fd)
c = d.cursor()
rec = c.first()
while rec:
if verbose:
- print rec
+ print(rec)
rec = c.next()
c.set(50)
rec = c.current()
if verbose:
- print rec
+ print(rec)
c.put(-1, "a replacement record", db.DB_CURRENT)
@@ -144,18 +144,18 @@ class SimpleRecnoTestCase(unittest.TestCase):
rec = c.current()
assert rec == (50, "a replacement record")
if verbose:
- print rec
+ print(rec)
rec = c.set_range(30)
if verbose:
- print rec
+ print(rec)
# test that non-existant key lookups work (and that
# DBC_set_range doesn't have a memleak under valgrind)
rec = c.set_range(999999)
assert rec == None
if verbose:
- print rec
+ print(rec)
c.close()
d.close()
@@ -182,7 +182,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
self.fail("unexpected DBKeyEmptyError exception")
else:
assert val[0] == db.DB_KEYEMPTY
- if verbose: print val
+ if verbose: print(val)
else:
if not get_returns_none:
self.fail("expected exception")
@@ -190,7 +190,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
rec = c.set(40)
while rec:
if verbose:
- print rec
+ print(rec)
rec = c.next()
c.close()
@@ -227,9 +227,9 @@ class SimpleRecnoTestCase(unittest.TestCase):
text = open(source, 'r').read()
text = text.strip()
if verbose:
- print text
- print data
- print text.split('\n')
+ print(text)
+ print(data)
+ print(text.split('\n'))
assert text.split('\n') == data
@@ -247,8 +247,8 @@ class SimpleRecnoTestCase(unittest.TestCase):
text = open(source, 'r').read()
text = text.strip()
if verbose:
- print text
- print text.split('\n')
+ print(text)
+ print(text.split('\n'))
assert text.split('\n') == \
"The quick reddish-brown fox jumped over the comatose dog".split()
@@ -269,7 +269,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
d.append('bad' * 20)
except db.DBInvalidArgError as val:
assert val[0] == db.EINVAL
- if verbose: print val
+ if verbose: print(val)
else:
self.fail("expected exception")
@@ -277,7 +277,7 @@ class SimpleRecnoTestCase(unittest.TestCase):
rec = c.first()
while rec:
if verbose:
- print rec
+ print(rec)
rec = c.next()
c.close()
diff --git a/Lib/bsddb/test/test_thread.py b/Lib/bsddb/test/test_thread.py
index b3d7ef9..eabf96a 100644
--- a/Lib/bsddb/test/test_thread.py
+++ b/Lib/bsddb/test/test_thread.py
@@ -93,9 +93,9 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
def test01_1WriterMultiReaders(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test01_1WriterMultiReaders..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test01_1WriterMultiReaders..." % \
+ self.__class__.__name__)
threads = []
for x in range(self.writers):
@@ -123,17 +123,17 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
start = howMany * writerNum
stop = howMany * (writerNum + 1) - 1
if verbose:
- print "%s: creating records %d - %d" % (name, start, stop)
+ print("%s: creating records %d - %d" % (name, start, stop))
for x in range(start, stop):
key = '%04d' % x
dbutils.DeadlockWrap(d.put, key, self.makeData(key),
max_retries=12)
if verbose and x % 100 == 0:
- print "%s: records %d - %d finished" % (name, start, x)
+ print("%s: records %d - %d finished" % (name, start, x))
if verbose:
- print "%s: finished creating records" % name
+ print("%s: finished creating records" % name)
## # Each write-cursor will be exclusive, the only one that can update the DB...
## if verbose: print "%s: deleting a few records" % name
@@ -147,7 +147,7 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
## c.close()
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
def readerThread(self, d, readerNum):
time.sleep(0.01 * readerNum)
@@ -163,12 +163,12 @@ class ConcurrentDataStoreBase(BaseThreadedTestCase):
self.assertEqual(self.makeData(key), data)
rec = c.next()
if verbose:
- print "%s: found %d records" % (name, count)
+ print("%s: found %d records" % (name, count))
c.close()
time.sleep(0.05)
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
class BTreeConcurrentDataStore(ConcurrentDataStoreBase):
@@ -199,8 +199,8 @@ class SimpleThreadedBase(BaseThreadedTestCase):
def test02_SimpleLocks(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test02_SimpleLocks..." % self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test02_SimpleLocks..." % self.__class__.__name__)
threads = []
for x in range(self.writers):
@@ -226,7 +226,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
start = howMany * writerNum
stop = howMany * (writerNum + 1) - 1
if verbose:
- print "%s: creating records %d - %d" % (name, start, stop)
+ print("%s: creating records %d - %d" % (name, start, stop))
# create a bunch of records
for x in xrange(start, stop):
@@ -235,7 +235,7 @@ class SimpleThreadedBase(BaseThreadedTestCase):
max_retries=12)
if verbose and x % 100 == 0:
- print "%s: records %d - %d finished" % (name, start, x)
+ print("%s: records %d - %d finished" % (name, start, x))
# do a bit or reading too
if random() <= 0.05:
@@ -249,22 +249,22 @@ class SimpleThreadedBase(BaseThreadedTestCase):
dbutils.DeadlockWrap(d.sync, max_retries=12)
except db.DBIncompleteError as val:
if verbose:
- print "could not complete sync()..."
+ print("could not complete sync()...")
# read them back, deleting a few
for x in xrange(start, stop):
key = '%04d' % x
data = dbutils.DeadlockWrap(d.get, key, max_retries=12)
if verbose and x % 100 == 0:
- print "%s: fetched record (%s, %s)" % (name, key, data)
+ print("%s: fetched record (%s, %s)" % (name, key, data))
self.assertEqual(data, self.makeData(key))
if random() <= 0.10:
dbutils.DeadlockWrap(d.delete, key, max_retries=12)
if verbose:
- print "%s: deleted record %s" % (name, key)
+ print("%s: deleted record %s" % (name, key))
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
def readerThread(self, d, readerNum):
time.sleep(0.01 * readerNum)
@@ -280,12 +280,12 @@ class SimpleThreadedBase(BaseThreadedTestCase):
self.assertEqual(self.makeData(key), data)
rec = dbutils.DeadlockWrap(c.next, max_retries=10)
if verbose:
- print "%s: found %d records" % (name, count)
+ print("%s: found %d records" % (name, count))
c.close()
time.sleep(0.05)
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
class BTreeSimpleThreaded(SimpleThreadedBase):
@@ -318,9 +318,9 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
def test03_ThreadedTransactions(self):
if verbose:
- print '\n', '-=' * 30
- print "Running %s.test03_ThreadedTransactions..." % \
- self.__class__.__name__
+ print('\n', '-=' * 30)
+ print("Running %s.test03_ThreadedTransactions..." % \
+ self.__class__.__name__)
threads = []
for x in range(self.writers):
@@ -357,12 +357,12 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
key = '%04d' % x
d.put(key, self.makeData(key), txn)
if verbose and x % 100 == 0:
- print "%s: records %d - %d finished" % (name, start, x)
+ print("%s: records %d - %d finished" % (name, start, x))
txn.commit()
finished = True
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose:
- print "%s: Aborting transaction (%s)" % (name, val[1])
+ print("%s: Aborting transaction (%s)" % (name, val[1]))
txn.abort()
time.sleep(0.05)
@@ -371,16 +371,16 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
start = howMany * writerNum
stop = howMany * (writerNum + 1) - 1
if verbose:
- print "%s: creating records %d - %d" % (name, start, stop)
+ print("%s: creating records %d - %d" % (name, start, stop))
step = 100
for x in range(start, stop, step):
self.doWrite(d, name, x, min(stop, x+step))
if verbose:
- print "%s: finished creating records" % name
+ print("%s: finished creating records" % name)
if verbose:
- print "%s: deleting a few records" % name
+ print("%s: deleting a few records" % name)
finished = False
while not finished:
@@ -397,15 +397,15 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
txn.commit()
finished = True
if verbose:
- print "%s: deleted records %s" % (name, recs)
+ print("%s: deleted records %s" % (name, recs))
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose:
- print "%s: Aborting transaction (%s)" % (name, val[1])
+ print("%s: Aborting transaction (%s)" % (name, val[1]))
txn.abort()
time.sleep(0.05)
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
def readerThread(self, d, readerNum):
time.sleep(0.01 * readerNum + 0.05)
@@ -424,13 +424,13 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
key, data = rec
self.assertEqual(self.makeData(key), data)
rec = c.next()
- if verbose: print "%s: found %d records" % (name, count)
+ if verbose: print("%s: found %d records" % (name, count))
c.close()
txn.commit()
finished = True
except (db.DBLockDeadlockError, db.DBLockNotGrantedError) as val:
if verbose:
- print "%s: Aborting transaction (%s)" % (name, val[1])
+ print("%s: Aborting transaction (%s)" % (name, val[1]))
c.close()
txn.abort()
time.sleep(0.05)
@@ -438,7 +438,7 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
time.sleep(0.05)
if verbose:
- print "%s: thread finished" % name
+ print("%s: thread finished" % name)
def deadlockThread(self):
self.doLockDetect = True
@@ -448,8 +448,8 @@ class ThreadedTransactionsBase(BaseThreadedTestCase):
aborted = self.env.lock_detect(
db.DB_LOCK_RANDOM, db.DB_LOCK_CONFLICT)
if verbose and aborted:
- print "deadlock: Aborted %d deadlocked transaction(s)" \
- % aborted
+ print("deadlock: Aborted %d deadlocked transaction(s)" \
+ % aborted)
except db.DBError:
pass
@@ -497,7 +497,7 @@ def test_suite():
suite.addTest(unittest.makeSuite(HashThreadedNoWaitTransactions))
else:
- print "Threads not available, skipping thread tests."
+ print("Threads not available, skipping thread tests.")
return suite