Port BerkeleyDB 4.1 support from the pybsddb project. bsddb is now at
version 4.1.1 and works with up to BerkeleyDB 4.1.25.
diff --git a/Lib/bsddb/test/__init__.py b/Lib/bsddb/test/__init__.py
index 6e1c4ed..e69de29 100644
--- a/Lib/bsddb/test/__init__.py
+++ b/Lib/bsddb/test/__init__.py
@@ -1 +0,0 @@
-# PyBSDDB test suite
diff --git a/Lib/bsddb/test/test_all.py b/Lib/bsddb/test/test_all.py
new file mode 100644
index 0000000..15b310f
--- /dev/null
+++ b/Lib/bsddb/test/test_all.py
@@ -0,0 +1,76 @@
+"""Run all test cases.
+"""
+
+import sys
+import os
+import unittest
+
+verbose = 0
+if 'verbose' in sys.argv:
+ verbose = 1
+ sys.argv.remove('verbose')
+
+if 'silent' in sys.argv: # take care of old flag, just in case
+ verbose = 0
+ sys.argv.remove('silent')
+
+
+def print_versions():
+ from bsddb import db
+ 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):
+ def testPrintVersions(self):
+ print_versions()
+
+
+# This little hack is for when this module is run as main and all the
+# other modules import it so they will still be able to get the right
+# verbose setting. It's confusing but it works.
+import test_all
+test_all.verbose = verbose
+
+
+def suite():
+ test_modules = [
+ 'test_associate',
+ 'test_basics',
+ 'test_compat',
+ 'test_dbobj',
+ 'test_dbshelve',
+ 'test_dbtables',
+ 'test_env_close',
+ 'test_get_none',
+ 'test_join',
+ 'test_lock',
+ 'test_misc',
+ 'test_queue',
+ 'test_recno',
+ 'test_thread',
+ ]
+
+ alltests = unittest.TestSuite()
+ for name in test_modules:
+ module = __import__(name)
+ alltests.addTest(module.suite())
+ return alltests
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(PrintInfoFakeTest))
+ return suite
+
+
+if __name__ == '__main__':
+ print_versions()
+ unittest.main(defaultTest='suite')
diff --git a/Lib/bsddb/test/test_associate.py b/Lib/bsddb/test/test_associate.py
index 305a794..7f1df83 100644
--- a/Lib/bsddb/test/test_associate.py
+++ b/Lib/bsddb/test/test_associate.py
@@ -14,7 +14,7 @@
have_threads = 0
import unittest
-from test.test_support import verbose
+from test_all import verbose
from bsddb import db, dbshelve
@@ -70,7 +70,8 @@
45: ("Blue Man Group", "Klein Mandelbrot", "New Age"),
46: ("Kenny G", "Silhouette", "Jazz"),
47: ("Sade", "Smooth Operator", "Jazz"),
-48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)", "New Age"),
+48: ("David Arkenstone", "Papillon (On The Wings Of The Butterfly)",
+ "New Age"),
49: ("David Arkenstone", "Stepping Stars", "New Age"),
50: ("David Arkenstone", "Carnation Lily Lily Rose", "New Age"),
51: ("David Lanz", "Behind The Waterfall", "New Age"),
@@ -109,8 +110,6 @@
key = "%02d" % key
d.put(key, string.join(value, '|'))
-
-
def createDB(self):
self.primary = db.DB(self.env)
self.primary.open(self.filename, "primary", self.dbtype,
@@ -122,18 +121,18 @@
def getDB(self):
return self.primary
-
-
def test01_associateWithDB(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test01_associateWithDB..." % self.__class__.__name__
+ print "Running %s.test01_associateWithDB..." % \
+ self.__class__.__name__
self.createDB()
secDB = db.DB(self.env)
secDB.set_flags(db.DB_DUP)
- secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE | db.DB_THREAD)
+ secDB.open(self.filename, "secondary", db.DB_BTREE,
+ db.DB_CREATE | db.DB_THREAD)
self.getDB().associate(secDB, self.getGenre)
self.addDataToDB(self.getDB())
@@ -144,14 +143,16 @@
def test02_associateAfterDB(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test02_associateAfterDB..." % self.__class__.__name__
+ print "Running %s.test02_associateAfterDB..." % \
+ self.__class__.__name__
self.createDB()
self.addDataToDB(self.getDB())
secDB = db.DB(self.env)
secDB.set_flags(db.DB_DUP)
- secDB.open(self.filename, "secondary", db.DB_BTREE, db.DB_CREATE | db.DB_THREAD)
+ secDB.open(self.filename, "secondary", db.DB_BTREE,
+ db.DB_CREATE | db.DB_THREAD)
# adding the DB_CREATE flag will cause it to index existing records
self.getDB().associate(secDB, self.getGenre, db.DB_CREATE)
@@ -159,8 +160,6 @@
self.finish_test(secDB)
-
-
def finish_test(self, secDB):
if verbose:
print "Primary key traversal:"
@@ -190,9 +189,8 @@
if verbose:
print rec
rec = c.next()
- assert count == len(musicdata)-1 # all items accounted for EXCEPT for 1 with "Blues" genre
-
-
+ # all items accounted for EXCEPT for 1 with "Blues" genre
+ assert count == len(musicdata)-1
def getGenre(self, priKey, priData):
assert type(priData) == type("")
@@ -299,25 +297,25 @@
#----------------------------------------------------------------------
-def suite():
- theSuite = unittest.TestSuite()
+def test_suite():
+ suite = unittest.TestSuite()
if db.version() >= (3, 3, 11):
- theSuite.addTest(unittest.makeSuite(AssociateHashTestCase))
- theSuite.addTest(unittest.makeSuite(AssociateBTreeTestCase))
- theSuite.addTest(unittest.makeSuite(AssociateRecnoTestCase))
+ suite.addTest(unittest.makeSuite(AssociateHashTestCase))
+ suite.addTest(unittest.makeSuite(AssociateBTreeTestCase))
+ suite.addTest(unittest.makeSuite(AssociateRecnoTestCase))
- theSuite.addTest(unittest.makeSuite(ShelveAssociateHashTestCase))
- theSuite.addTest(unittest.makeSuite(ShelveAssociateBTreeTestCase))
- theSuite.addTest(unittest.makeSuite(ShelveAssociateRecnoTestCase))
+ suite.addTest(unittest.makeSuite(ShelveAssociateHashTestCase))
+ suite.addTest(unittest.makeSuite(ShelveAssociateBTreeTestCase))
+ suite.addTest(unittest.makeSuite(ShelveAssociateRecnoTestCase))
if have_threads:
- theSuite.addTest(unittest.makeSuite(ThreadedAssociateHashTestCase))
- theSuite.addTest(unittest.makeSuite(ThreadedAssociateBTreeTestCase))
- theSuite.addTest(unittest.makeSuite(ThreadedAssociateRecnoTestCase))
+ suite.addTest(unittest.makeSuite(ThreadedAssociateHashTestCase))
+ suite.addTest(unittest.makeSuite(ThreadedAssociateBTreeTestCase))
+ suite.addTest(unittest.makeSuite(ThreadedAssociateRecnoTestCase))
- return theSuite
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py
index f2ccb8a..37f4d11 100644
--- a/Lib/bsddb/test/test_basics.py
+++ b/Lib/bsddb/test/test_basics.py
@@ -3,14 +3,20 @@
various DB flags, etc.
"""
-import sys, os, string
+import os
+import sys
+import errno
+import shutil
+import string
import tempfile
from pprint import pprint
import unittest
from bsddb import db
-from test.test_support import verbose
+from test_all import verbose
+
+DASH = '-'
#----------------------------------------------------------------------
@@ -23,7 +29,8 @@
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)
+ assert info == (db.DB_VERSION_MAJOR, db.DB_VERSION_MINOR,
+ db.DB_VERSION_PATCH)
#----------------------------------------------------------------------
@@ -35,19 +42,30 @@
dbname = None
useEnv = 0
envflags = 0
+ envsetflags = 0
def setUp(self):
if self.useEnv:
homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
- try: os.mkdir(homeDir)
- except os.error: pass
- self.env = db.DBEnv()
- self.env.set_lg_max(1024*1024)
- self.env.open(homeDir, self.envflags | db.DB_CREATE)
- tempfile.tempdir = homeDir
- self.filename = os.path.split(tempfile.mktemp())[1]
- tempfile.tempdir = None
self.homeDir = homeDir
+ try:
+ shutil.rmtree(homeDir)
+ except OSError, e:
+ # unix returns ENOENT, windows returns ESRCH
+ if e.errno not in (errno.ENOENT, errno.ESRCH): raise
+ os.mkdir(homeDir)
+ try:
+ self.env = db.DBEnv()
+ self.env.set_lg_max(1024*1024)
+ self.env.set_flags(self.envsetflags, 1)
+ self.env.open(homeDir, self.envflags | db.DB_CREATE)
+ tempfile.tempdir = homeDir
+ self.filename = os.path.split(tempfile.mktemp())[1]
+ tempfile.tempdir = None
+ # Yes, a bare except is intended, since we're re-raising the exc.
+ except:
+ shutil.rmtree(homeDir)
+ raise
else:
self.env = None
self.filename = tempfile.mktemp()
@@ -61,7 +79,8 @@
else:
self.d.open(self.filename, # try out keyword args
mode = self.dbmode,
- dbtype = self.dbtype, flags = self.dbopenflags|db.DB_CREATE)
+ dbtype = self.dbtype,
+ flags = self.dbopenflags|db.DB_CREATE)
self.populateDB()
@@ -70,19 +89,13 @@
self.d.close()
if self.env is not None:
self.env.close()
-
- import glob
- files = glob.glob(os.path.join(self.homeDir, '*'))
- for file in files:
- os.remove(file)
-
+ shutil.rmtree(self.homeDir)
## Make a new DBEnv to remove the env files from the home dir.
## (It can't be done while the env is open, nor after it has been
## closed, so we make a new one to do it.)
#e = db.DBEnv()
#e.remove(self.homeDir)
#os.remove(os.path.join(self.homeDir, self.filename))
-
else:
os.remove(self.filename)
@@ -106,7 +119,7 @@
def makeData(self, key):
- return string.join([key] * 5, '-')
+ return DASH.join([key] * 5)
@@ -209,7 +222,8 @@
if verbose:
print '\n', '-=' * 30
- print "Running %s.test02_DictionaryMethods..." % self.__class__.__name__
+ print "Running %s.test02_DictionaryMethods..." % \
+ self.__class__.__name__
for key in ['0002', '0101', '0401', '0701', '0998']:
data = d[key]
@@ -266,10 +280,14 @@
def test03_SimpleCursorStuff(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test03_SimpleCursorStuff..." % self.__class__.__name__
+ print "Running %s.test03_SimpleCursorStuff..." % \
+ self.__class__.__name__
- c = self.d.cursor()
-
+ if self.env and self.dbopenflags & db.DB_AUTO_COMMIT:
+ txn = self.env.txn_begin()
+ else:
+ txn = None
+ c = self.d.cursor(txn=txn)
rec = c.first()
count = 0
@@ -350,6 +368,8 @@
c.close()
c2.close()
+ if txn:
+ txn.commit()
# time to abuse the closed cursors and hope we don't crash
methods_to_test = {
@@ -367,14 +387,16 @@
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...
apply(getattr(c, method), args)
except db.DBError, val:
assert val[0] == 0
if verbose: print val
else:
- self.fail("no exception raised when using a buggy cursor's %s method" % method)
+ self.fail("no exception raised when using a buggy cursor's"
+ "%s method" % method)
#----------------------------------------
@@ -382,7 +404,8 @@
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test04_PartialGetAndPut..." % self.__class__.__name__
+ print "Running %s.test04_PartialGetAndPut..." % \
+ self.__class__.__name__
key = "partialTest"
data = "1" * 1000 + "2" * 1000
@@ -393,7 +416,8 @@
d.put("partialtest2", ("1" * 30000) + "robin" )
assert d.get("partialtest2", dlen=5, doff=30000) == "robin"
- # There seems to be a bug in DB here... Commented out the test for now.
+ # There seems to be a bug in DB here... Commented out the test for
+ # now.
##assert d.get("partialtest2", dlen=5, doff=30010) == ""
if self.dbsetflags != db.DB_DUP:
@@ -423,6 +447,10 @@
#----------------------------------------
def test06_Truncate(self):
+ if db.version() < (3,3):
+ # truncate is a feature of BerkeleyDB 3.3 and above
+ return
+
d = self.d
if verbose:
print '\n', '-=' * 30
@@ -472,9 +500,11 @@
#----------------------------------------------------------------------
class BasicTransactionTestCase(BasicTestCase):
- dbopenflags = db.DB_THREAD
+ dbopenflags = db.DB_THREAD | db.DB_AUTO_COMMIT
useEnv = 1
- envflags = db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK | db.DB_INIT_TXN
+ envflags = (db.DB_THREAD | db.DB_INIT_MPOOL | db.DB_INIT_LOCK |
+ db.DB_INIT_TXN)
+ envsetflags = db.DB_AUTO_COMMIT
def tearDown(self):
@@ -557,6 +587,10 @@
#----------------------------------------
def test07_TxnTruncate(self):
+ if db.version() < (3,3):
+ # truncate is a feature of BerkeleyDB 3.3 and above
+ return
+
d = self.d
if verbose:
print '\n', '-=' * 30
@@ -624,10 +658,11 @@
d = self.d
if verbose:
print '\n', '-=' * 30
- print "Running %s.test08_DuplicateKeys..." % self.__class__.__name__
+ print "Running %s.test08_DuplicateKeys..." % \
+ self.__class__.__name__
d.put("dup0", "before")
- for x in string.split("The quick brown fox jumped over the lazy dog."):
+ for x in "The quick brown fox jumped over the lazy dog.".split():
d.put("dup1", x)
d.put("dup2", "after")
@@ -699,11 +734,13 @@
print "Running %s.test09_MultiDB..." % self.__class__.__name__
d2 = db.DB(self.env)
- d2.open(self.filename, "second", self.dbtype, self.dbopenflags|db.DB_CREATE)
+ d2.open(self.filename, "second", self.dbtype,
+ self.dbopenflags|db.DB_CREATE)
d3 = db.DB(self.env)
- d3.open(self.filename, "third", self.otherType(), self.dbopenflags|db.DB_CREATE)
+ d3.open(self.filename, "third", self.otherType(),
+ self.dbopenflags|db.DB_CREATE)
- for x in string.split("The quick brown fox jumped over the lazy dog"):
+ for x in "The quick brown fox jumped over the lazy dog".split():
d2.put(x, self.makeData(x))
for x in string.letters:
@@ -785,29 +822,29 @@
#----------------------------------------------------------------------
#----------------------------------------------------------------------
-def suite():
- theSuite = unittest.TestSuite()
+def test_suite():
+ suite = unittest.TestSuite()
- theSuite.addTest(unittest.makeSuite(VersionTestCase))
- theSuite.addTest(unittest.makeSuite(BasicBTreeTestCase))
- theSuite.addTest(unittest.makeSuite(BasicHashTestCase))
- theSuite.addTest(unittest.makeSuite(BasicBTreeWithThreadFlagTestCase))
- theSuite.addTest(unittest.makeSuite(BasicHashWithThreadFlagTestCase))
- theSuite.addTest(unittest.makeSuite(BasicBTreeWithEnvTestCase))
- theSuite.addTest(unittest.makeSuite(BasicHashWithEnvTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeTransactionTestCase))
- theSuite.addTest(unittest.makeSuite(HashTransactionTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeRecnoTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeRecnoWithThreadFlagTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeDUPTestCase))
- theSuite.addTest(unittest.makeSuite(HashDUPTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeDUPWithThreadTestCase))
- theSuite.addTest(unittest.makeSuite(HashDUPWithThreadTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeMultiDBTestCase))
- theSuite.addTest(unittest.makeSuite(HashMultiDBTestCase))
+ suite.addTest(unittest.makeSuite(VersionTestCase))
+ suite.addTest(unittest.makeSuite(BasicBTreeTestCase))
+ suite.addTest(unittest.makeSuite(BasicHashTestCase))
+ suite.addTest(unittest.makeSuite(BasicBTreeWithThreadFlagTestCase))
+ suite.addTest(unittest.makeSuite(BasicHashWithThreadFlagTestCase))
+ suite.addTest(unittest.makeSuite(BasicBTreeWithEnvTestCase))
+ suite.addTest(unittest.makeSuite(BasicHashWithEnvTestCase))
+ suite.addTest(unittest.makeSuite(BTreeTransactionTestCase))
+ suite.addTest(unittest.makeSuite(HashTransactionTestCase))
+ suite.addTest(unittest.makeSuite(BTreeRecnoTestCase))
+ suite.addTest(unittest.makeSuite(BTreeRecnoWithThreadFlagTestCase))
+ suite.addTest(unittest.makeSuite(BTreeDUPTestCase))
+ suite.addTest(unittest.makeSuite(HashDUPTestCase))
+ suite.addTest(unittest.makeSuite(BTreeDUPWithThreadTestCase))
+ suite.addTest(unittest.makeSuite(HashDUPWithThreadTestCase))
+ suite.addTest(unittest.makeSuite(BTreeMultiDBTestCase))
+ suite.addTest(unittest.makeSuite(HashMultiDBTestCase))
- return theSuite
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_compat.py b/Lib/bsddb/test/test_compat.py
index 2514d02..862ec74 100644
--- a/Lib/bsddb/test/test_compat.py
+++ b/Lib/bsddb/test/test_compat.py
@@ -9,7 +9,7 @@
import unittest
import tempfile
-from test.test_support import verbose
+from test_all import verbose
@@ -159,9 +159,9 @@
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(CompatibilityTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_dbobj.py b/Lib/bsddb/test/test_dbobj.py
index c1b82fe..1e1ac27 100644
--- a/Lib/bsddb/test/test_dbobj.py
+++ b/Lib/bsddb/test/test_dbobj.py
@@ -36,18 +36,20 @@
# call our parent classes put method with an upper case key
return apply(dbobj.DB.put, (self, key) + args, kwargs)
self.env = TestDBEnv()
- self.env.open(self.db_home, db.DB_CREATE | db.DB_INIT_MPOOL)
+ self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
self.db = TestDB(self.env)
self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE)
self.db.put('spam', 'eggs')
- assert self.db.get('spam') == None, "overridden dbobj.DB.put() method failed [1]"
- assert self.db.get('SPAM') == 'eggs', "overridden dbobj.DB.put() method failed [2]"
+ assert self.db.get('spam') == None, \
+ "overridden dbobj.DB.put() method failed [1]"
+ assert self.db.get('SPAM') == 'eggs', \
+ "overridden dbobj.DB.put() method failed [2]"
self.db.close()
self.env.close()
def test02_dbobj_dict_interface(self):
self.env = dbobj.DBEnv()
- self.env.open(self.db_home, db.DB_CREATE | db.DB_INIT_MPOOL)
+ self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
self.db = dbobj.DB(self.env)
self.db.open(self.db_name+'02', db.DB_HASH, db.DB_CREATE)
# __setitem__
@@ -64,8 +66,8 @@
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(dbobjTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_dbshelve.py b/Lib/bsddb/test/test_dbshelve.py
index 7705882..900ec8e 100644
--- a/Lib/bsddb/test/test_dbshelve.py
+++ b/Lib/bsddb/test/test_dbshelve.py
@@ -10,7 +10,7 @@
from bsddb import dbshelve, db
-from test.test_support import verbose
+from test_all import verbose
#----------------------------------------------------------------------
@@ -143,6 +143,7 @@
key, value = rec
self.checkrec(key, value)
rec = c.next()
+ del c
assert count == len(d)
@@ -162,9 +163,7 @@
c.set('SS')
key, value = c.current()
self.checkrec(key, value)
-
- c.close()
-
+ del c
@@ -202,8 +201,6 @@
self.d.close()
-
-
class BTreeShelveTestCase(BasicShelveTestCase):
dbtype = db.DB_BTREE
dbflags = db.DB_CREATE
@@ -228,7 +225,8 @@
class BasicEnvShelveTestCase(DBShelveTestCase):
def do_open(self):
- self.homeDir = homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
+ self.homeDir = homeDir = os.path.join(
+ os.path.dirname(sys.argv[0]), 'db_home')
try: os.mkdir(homeDir)
except os.error: pass
self.env = db.DBEnv()
@@ -283,21 +281,21 @@
#----------------------------------------------------------------------
-def suite():
- theSuite = unittest.TestSuite()
+def test_suite():
+ suite = unittest.TestSuite()
- theSuite.addTest(unittest.makeSuite(DBShelveTestCase))
- theSuite.addTest(unittest.makeSuite(BTreeShelveTestCase))
- theSuite.addTest(unittest.makeSuite(HashShelveTestCase))
- theSuite.addTest(unittest.makeSuite(ThreadBTreeShelveTestCase))
- theSuite.addTest(unittest.makeSuite(ThreadHashShelveTestCase))
- theSuite.addTest(unittest.makeSuite(EnvBTreeShelveTestCase))
- theSuite.addTest(unittest.makeSuite(EnvHashShelveTestCase))
- theSuite.addTest(unittest.makeSuite(EnvThreadBTreeShelveTestCase))
- theSuite.addTest(unittest.makeSuite(EnvThreadHashShelveTestCase))
+ suite.addTest(unittest.makeSuite(DBShelveTestCase))
+ suite.addTest(unittest.makeSuite(BTreeShelveTestCase))
+ suite.addTest(unittest.makeSuite(HashShelveTestCase))
+ suite.addTest(unittest.makeSuite(ThreadBTreeShelveTestCase))
+ suite.addTest(unittest.makeSuite(ThreadHashShelveTestCase))
+ suite.addTest(unittest.makeSuite(EnvBTreeShelveTestCase))
+ suite.addTest(unittest.makeSuite(EnvHashShelveTestCase))
+ suite.addTest(unittest.makeSuite(EnvThreadBTreeShelveTestCase))
+ suite.addTest(unittest.makeSuite(EnvThreadHashShelveTestCase))
- return theSuite
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_dbtables.py b/Lib/bsddb/test/test_dbtables.py
index bfa7586..a250cf8 100644
--- a/Lib/bsddb/test/test_dbtables.py
+++ b/Lib/bsddb/test/test_dbtables.py
@@ -28,7 +28,7 @@
import pickle
import unittest
-from test.test_support import verbose
+from test_all import verbose
from bsddb import db, dbtables
@@ -45,7 +45,8 @@
self.homeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
- self.tdb = dbtables.bsdTableDB(filename='tabletest.db', dbhome='db_home', create=1)
+ self.tdb = dbtables.bsdTableDB(
+ filename='tabletest.db', dbhome=homeDir, create=1)
def tearDown(self):
self.tdb.close()
@@ -67,7 +68,8 @@
if verbose:
self.tdb._db_print()
- values = self.tdb.Select(tabname, [colname], conditions={colname: None})
+ values = self.tdb.Select(
+ tabname, [colname], conditions={colname: None})
colval = pickle.loads(values[0][colname])
assert(colval > 3.141 and colval < 3.142)
@@ -125,7 +127,10 @@
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e'])
try:
- self.tdb.Insert(tabname, {'a': "", 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1), 'f': "Zero"})
+ self.tdb.Insert(tabname,
+ {'a': "",
+ 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1),
+ 'f': "Zero"})
assert 0
except dbtables.TableDBError:
pass
@@ -136,21 +141,38 @@
except dbtables.TableDBError:
pass
- self.tdb.Insert(tabname, {'a': '42', 'b': "bad", 'c': "meep", 'e': 'Fuzzy wuzzy was a bear'})
- self.tdb.Insert(tabname, {'a': '581750', 'b': "good", 'd': "bla", 'c': "black", 'e': 'fuzzy was here'})
- self.tdb.Insert(tabname, {'a': '800000', 'b': "good", 'd': "bla", 'c': "black", 'e': 'Fuzzy wuzzy is a bear'})
+ self.tdb.Insert(tabname,
+ {'a': '42',
+ 'b': "bad",
+ 'c': "meep",
+ 'e': 'Fuzzy wuzzy was a bear'})
+ self.tdb.Insert(tabname,
+ {'a': '581750',
+ 'b': "good",
+ 'd': "bla",
+ 'c': "black",
+ 'e': 'fuzzy was here'})
+ self.tdb.Insert(tabname,
+ {'a': '800000',
+ 'b': "good",
+ 'd': "bla",
+ 'c': "black",
+ 'e': 'Fuzzy wuzzy is a bear'})
if verbose:
self.tdb._db_print()
# this should return two rows
values = self.tdb.Select(tabname, ['b', 'a', 'd'],
- conditions={'e': re.compile('wuzzy').search, 'a': re.compile('^[0-9]+$').match})
+ conditions={'e': re.compile('wuzzy').search,
+ 'a': re.compile('^[0-9]+$').match})
assert len(values) == 2
# now lets delete one of them and try again
self.tdb.Delete(tabname, conditions={'b': dbtables.ExactCond('good')})
- values = self.tdb.Select(tabname, ['a', 'd', 'b'], conditions={'e': dbtables.PrefixCond('Fuzzy')})
+ values = self.tdb.Select(
+ tabname, ['a', 'd', 'b'],
+ conditions={'e': dbtables.PrefixCond('Fuzzy')})
assert len(values) == 1
assert values[0]['d'] == None
@@ -169,14 +191,20 @@
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e'])
try:
- self.tdb.Insert(tabname, {'a': "", 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1), 'f': "Zero"})
+ self.tdb.Insert(tabname,
+ {'a': "",
+ 'e': pickle.dumps([{4:5, 6:7}, 'foo'], 1),
+ 'f': "Zero"})
assert 0
except dbtables.TableDBError:
pass
- self.tdb.Insert(tabname, {'a': "A", 'b': "B", 'c': "C", 'd': "D", 'e': "E"})
- self.tdb.Insert(tabname, {'a': "-A", 'b': "-B", 'c': "-C", 'd': "-D", 'e': "-E"})
- self.tdb.Insert(tabname, {'a': "A-", 'b': "B-", 'c': "C-", 'd': "D-", 'e': "E-"})
+ self.tdb.Insert(tabname, {'a': "A", 'b': "B", 'c': "C", 'd': "D",
+ 'e': "E"})
+ self.tdb.Insert(tabname, {'a': "-A", 'b': "-B", 'c': "-C", 'd': "-D",
+ 'e': "-E"})
+ self.tdb.Insert(tabname, {'a': "A-", 'b': "B-", 'c': "C-", 'd': "D-",
+ 'e': "E-"})
if verbose:
self.tdb._db_print()
@@ -197,17 +225,25 @@
def test_CreateOrExtend(self):
tabname = "test_CreateOrExtend"
- self.tdb.CreateOrExtendTable(tabname, ['name', 'taste', 'filling', 'alcohol content', 'price'])
+ self.tdb.CreateOrExtendTable(
+ tabname, ['name', 'taste', 'filling', 'alcohol content', 'price'])
try:
- self.tdb.Insert(tabname, {'taste': 'crap', 'filling': 'no', 'is it Guinness?': 'no'})
+ self.tdb.Insert(tabname,
+ {'taste': 'crap',
+ 'filling': 'no',
+ 'is it Guinness?': 'no'})
assert 0, "Insert should've failed due to bad column name"
except:
pass
- self.tdb.CreateOrExtendTable(tabname, ['name', 'taste', 'is it Guinness?'])
+ self.tdb.CreateOrExtendTable(tabname,
+ ['name', 'taste', 'is it Guinness?'])
# these should both succeed as the table should contain the union of both sets of columns.
- self.tdb.Insert(tabname, {'taste': 'crap', 'filling': 'no', 'is it Guinness?': 'no'})
- self.tdb.Insert(tabname, {'taste': 'great', 'filling': 'yes', 'is it Guinness?': 'yes', 'name': 'Guinness'})
+ self.tdb.Insert(tabname, {'taste': 'crap', 'filling': 'no',
+ 'is it Guinness?': 'no'})
+ self.tdb.Insert(tabname, {'taste': 'great', 'filling': 'yes',
+ 'is it Guinness?': 'yes',
+ 'name': 'Guinness'})
def test_CondObjs(self):
@@ -215,21 +251,39 @@
self.tdb.CreateTable(tabname, ['a', 'b', 'c', 'd', 'e', 'p'])
- self.tdb.Insert(tabname, {'a': "the letter A", 'b': "the letter B", 'c': "is for cookie"})
- self.tdb.Insert(tabname, {'a': "is for aardvark", 'e': "the letter E", 'c': "is for cookie", 'd': "is for dog"})
- self.tdb.Insert(tabname, {'a': "the letter A", 'e': "the letter E", 'c': "is for cookie", 'p': "is for Python"})
+ self.tdb.Insert(tabname, {'a': "the letter A",
+ 'b': "the letter B",
+ 'c': "is for cookie"})
+ self.tdb.Insert(tabname, {'a': "is for aardvark",
+ 'e': "the letter E",
+ 'c': "is for cookie",
+ 'd': "is for dog"})
+ self.tdb.Insert(tabname, {'a': "the letter A",
+ 'e': "the letter E",
+ 'c': "is for cookie",
+ 'p': "is for Python"})
- values = self.tdb.Select(tabname, ['p', 'e'], conditions={'e': dbtables.PrefixCond('the l')})
+ values = self.tdb.Select(
+ tabname, ['p', 'e'],
+ conditions={'e': dbtables.PrefixCond('the l')})
assert len(values) == 2, values
assert values[0]['e'] == values[1]['e'], values
assert values[0]['p'] != values[1]['p'], values
- values = self.tdb.Select(tabname, ['d', 'a'], conditions={'a': dbtables.LikeCond('%aardvark%')})
+ values = self.tdb.Select(
+ tabname, ['d', 'a'],
+ conditions={'a': dbtables.LikeCond('%aardvark%')})
assert len(values) == 1, values
assert values[0]['d'] == "is for dog", values
assert values[0]['a'] == "is for aardvark", values
- values = self.tdb.Select(tabname, None, {'b': dbtables.Cond(), 'e':dbtables.LikeCond('%letter%'), 'a':dbtables.PrefixCond('is'), 'd':dbtables.ExactCond('is for dog'), 'c':dbtables.PrefixCond('is for'), 'p':lambda s: not s})
+ values = self.tdb.Select(tabname, None,
+ {'b': dbtables.Cond(),
+ 'e':dbtables.LikeCond('%letter%'),
+ 'a':dbtables.PrefixCond('is'),
+ 'd':dbtables.ExactCond('is for dog'),
+ 'c':dbtables.PrefixCond('is for'),
+ 'p':lambda s: not s})
assert len(values) == 1, values
assert values[0]['d'] == "is for dog", values
assert values[0]['a'] == "is for aardvark", values
@@ -246,14 +300,16 @@
self.tdb.Insert(tabname, {'x': 'X2', 'y':'Y2', 'z': 'Z2'})
self.tdb.Delete(tabname, conditions={'x': dbtables.PrefixCond('X')})
- values = self.tdb.Select(tabname, ['y'], conditions={'x': dbtables.PrefixCond('X')})
+ values = self.tdb.Select(tabname, ['y'],
+ conditions={'x': dbtables.PrefixCond('X')})
assert len(values) == 0
def test_Modify(self):
tabname = "test_Modify"
self.tdb.CreateTable(tabname, ['Name', 'Type', 'Access'])
- self.tdb.Insert(tabname, {'Name': 'Index to MP3 files.doc', 'Type': 'Word', 'Access': '8'})
+ self.tdb.Insert(tabname, {'Name': 'Index to MP3 files.doc',
+ 'Type': 'Word', 'Access': '8'})
self.tdb.Insert(tabname, {'Name': 'Nifty.MP3', 'Access': '1'})
self.tdb.Insert(tabname, {'Type': 'Unknown', 'Access': '0'})
@@ -268,33 +324,45 @@
def remove_value(value):
return None
- self.tdb.Modify(tabname, conditions={'Access': dbtables.ExactCond('0')}, mappings={'Access': remove_value})
- self.tdb.Modify(tabname, conditions={'Name': dbtables.LikeCond('%MP3%')}, mappings={'Type': set_type})
- self.tdb.Modify(tabname, conditions={'Name': dbtables.LikeCond('%')}, mappings={'Access': increment_access})
+ self.tdb.Modify(tabname,
+ conditions={'Access': dbtables.ExactCond('0')},
+ mappings={'Access': remove_value})
+ self.tdb.Modify(tabname,
+ conditions={'Name': dbtables.LikeCond('%MP3%')},
+ mappings={'Type': set_type})
+ self.tdb.Modify(tabname,
+ conditions={'Name': dbtables.LikeCond('%')},
+ mappings={'Access': increment_access})
# Delete key in select conditions
- values = self.tdb.Select(tabname, None, conditions={'Type': dbtables.ExactCond('Unknown')})
+ values = self.tdb.Select(
+ tabname, None,
+ conditions={'Type': dbtables.ExactCond('Unknown')})
assert len(values) == 1, values
assert values[0]['Name'] == None, values
assert values[0]['Access'] == None, values
# Modify value by select conditions
- values = self.tdb.Select(tabname, None, conditions={'Name': dbtables.ExactCond('Nifty.MP3')})
+ values = self.tdb.Select(
+ tabname, None,
+ conditions={'Name': dbtables.ExactCond('Nifty.MP3')})
assert len(values) == 1, values
assert values[0]['Type'] == "MP3", values
assert values[0]['Access'] == "2", values
# Make sure change applied only to select conditions
- values = self.tdb.Select(tabname, None, conditions={'Name': dbtables.LikeCond('%doc%')})
+ values = self.tdb.Select(
+ tabname, None, conditions={'Name': dbtables.LikeCond('%doc%')})
assert len(values) == 1, values
assert values[0]['Type'] == "Word", values
assert values[0]['Access'] == "9", values
-def suite():
- theSuite = unittest.TestSuite()
- theSuite.addTest(unittest.makeSuite(TableDBTestCase))
- return theSuite
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TableDBTestCase))
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_env_close.py b/Lib/bsddb/test/test_env_close.py
index f6b0a0d..87ad97f 100644
--- a/Lib/bsddb/test/test_env_close.py
+++ b/Lib/bsddb/test/test_env_close.py
@@ -1,17 +1,27 @@
-"""
-TestCases for checking that it does not segfault when a DBEnv object
+"""TestCases for checking that it does not segfault when a DBEnv object
is closed before its DB objects.
"""
-import sys, os, string
-from pprint import pprint
+import os
+import sys
import tempfile
import glob
import unittest
from bsddb import db
-from test.test_support import verbose
+from test_all import verbose
+
+# We're going to get warnings in this module about trying to close the db when
+# its env is already closed. Let's just ignore those.
+try:
+ import warnings
+except ImportError:
+ pass
+else:
+ warnings.filterwarnings('ignore',
+ message='DB could not be closed in',
+ category=RuntimeWarning)
#----------------------------------------------------------------------
@@ -33,7 +43,9 @@
def test01_close_dbenv_before_db(self):
dbenv = db.DBEnv()
- dbenv.open(self.homeDir,db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, 0666)
+ dbenv.open(self.homeDir,
+ db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
+ 0666)
d = db.DB(dbenv)
d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
@@ -45,14 +57,18 @@
d.close()
except db.DBError:
return
- assert 0, "DB close did not raise an exception about its DBEnv being trashed"
+ assert 0, \
+ "DB close did not raise an exception about its "\
+ "DBEnv being trashed"
assert 0, "dbenv did not raise an exception about its DB being open"
def test02_close_dbenv_delete_db_success(self):
dbenv = db.DBEnv()
- dbenv.open(self.homeDir,db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL, 0666)
+ dbenv.open(self.homeDir,
+ db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
+ 0666)
d = db.DB(dbenv)
d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
@@ -62,8 +78,6 @@
except db.DBError:
pass # good, it should raise an exception
- # this should not raise an exception, it should silently skip
- # the db->close() call as it can't be done safely.
del d
try:
import gc
@@ -76,9 +90,11 @@
#----------------------------------------------------------------------
-def suite():
- return unittest.makeSuite(DBEnvClosedEarlyCrash)
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(DBEnvClosedEarlyCrash))
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_get_none.py b/Lib/bsddb/test/test_get_none.py
index 487bdf0..211717b 100644
--- a/Lib/bsddb/test/test_get_none.py
+++ b/Lib/bsddb/test/test_get_none.py
@@ -9,7 +9,7 @@
from bsddb import db
-from test.test_support import verbose
+from test_all import verbose
#----------------------------------------------------------------------
@@ -88,9 +88,9 @@
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(GetReturnsNoneTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_lock.py b/Lib/bsddb/test/test_lock.py
index 5483218..337a898 100644
--- a/Lib/bsddb/test/test_lock.py
+++ b/Lib/bsddb/test/test_lock.py
@@ -16,7 +16,7 @@
import unittest
-from test.test_support import verbose
+from test_all import verbose
from bsddb import db
@@ -68,15 +68,24 @@
print "Running %s.test02_threaded..." % self.__class__.__name__
threads = []
- threads.append(Thread(target = self.theThread, args=(5, db.DB_LOCK_WRITE)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_READ)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_READ)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_WRITE)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_READ)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_READ)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_WRITE)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_WRITE)))
- threads.append(Thread(target = self.theThread, args=(1, db.DB_LOCK_WRITE)))
+ threads.append(Thread(target = self.theThread,
+ args=(5, db.DB_LOCK_WRITE)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_READ)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_READ)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_WRITE)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_READ)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_READ)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_WRITE)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_WRITE)))
+ threads.append(Thread(target = self.theThread,
+ args=(1, db.DB_LOCK_WRITE)))
for t in threads:
t.start()
@@ -109,16 +118,16 @@
#----------------------------------------------------------------------
-def suite():
- theSuite = unittest.TestSuite()
+def test_suite():
+ suite = unittest.TestSuite()
if have_threads:
- theSuite.addTest(unittest.makeSuite(LockingTestCase))
+ suite.addTest(unittest.makeSuite(LockingTestCase))
else:
- theSuite.addTest(unittest.makeSuite(LockingTestCase, 'test01'))
+ suite.addTest(unittest.makeSuite(LockingTestCase, 'test01'))
- return theSuite
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_misc.py b/Lib/bsddb/test/test_misc.py
index 5d83a8e..24c3fc6 100644
--- a/Lib/bsddb/test/test_misc.py
+++ b/Lib/bsddb/test/test_misc.py
@@ -1,10 +1,8 @@
-"""
-Misc TestCases
+"""Miscellaneous bsddb module test cases
"""
-import sys, os, string
-import tempfile
-from pprint import pprint
+import os
+import sys
import unittest
from bsddb import db
@@ -19,25 +17,26 @@
self.filename = self.__class__.__name__ + '.db'
homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
self.homeDir = homeDir
- try: os.mkdir(homeDir)
- except os.error: pass
+ try:
+ os.mkdir(homeDir)
+ except OSError:
+ pass
def tearDown(self):
- try: os.remove(self.filename)
- except os.error: pass
+ try:
+ os.remove(self.filename)
+ except OSError:
+ pass
import glob
files = glob.glob(os.path.join(self.homeDir, '*'))
for file in files:
os.remove(file)
-
-
def test01_badpointer(self):
dbs = dbshelve.open(self.filename)
dbs.close()
self.assertRaises(db.DBError, dbs.get, "foo")
-
def test02_db_home(self):
env = db.DBEnv()
# check for crash fixed when db_home is used before open()
@@ -45,12 +44,13 @@
env.open(self.homeDir, db.DB_CREATE)
assert self.homeDir == env.db_home
+
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(MiscTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_queue.py b/Lib/bsddb/test/test_queue.py
index 6a92834..e651193 100644
--- a/Lib/bsddb/test/test_queue.py
+++ b/Lib/bsddb/test/test_queue.py
@@ -9,7 +9,7 @@
from bsddb import db
-from test.test_support import verbose
+from test_all import verbose
#----------------------------------------------------------------------
@@ -84,8 +84,8 @@
pprint(d.stat())
assert len(d) == 0, \
- "if you see this message then you need to rebuild BerkeleyDB 3.1.17 "\
- "with the patch in patches/qam_stat.diff"
+ "if you see this message then you need to rebuild " \
+ "BerkeleyDB 3.1.17 with the patch in patches/qam_stat.diff"
d.close()
@@ -160,9 +160,9 @@
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(SimpleQueueTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_recno.py b/Lib/bsddb/test/test_recno.py
index 40d9fca..a46dd91 100644
--- a/Lib/bsddb/test/test_recno.py
+++ b/Lib/bsddb/test/test_recno.py
@@ -2,14 +2,16 @@
TestCases for exercising a Recno DB.
"""
-import sys, os, string
+import os
+import sys
+import string
import tempfile
from pprint import pprint
import unittest
from bsddb import db
-from test.test_support import verbose
+from test_all import verbose
#----------------------------------------------------------------------
@@ -165,21 +167,24 @@
def test02_WithSource(self):
"""
- A Recno file that is given a "backing source file" is essentially a simple ASCII
- file. Normally each record is delimited by \n and so is just a line in the file,
- but you can set a different record delimiter if needed.
+ A Recno file that is given a "backing source file" is essentially a
+ simple ASCII file. Normally each record is delimited by \n and so is
+ just a line in the file, but you can set a different record delimiter
+ if needed.
"""
- source = os.path.join(os.path.dirname(sys.argv[0]), 'db_home/test_recno.txt')
+ source = os.path.join(os.path.dirname(sys.argv[0]),
+ 'db_home/test_recno.txt')
f = open(source, 'w') # create the file
f.close()
d = db.DB()
- d.set_re_delim(0x0A) # This is the default value, just checking if both int
+ # This is the default value, just checking if both int
+ d.set_re_delim(0x0A)
d.set_re_delim('\n') # and char can be used...
d.set_re_source(source)
d.open(self.filename, db.DB_RECNO, db.DB_CREATE)
- data = string.split("The quick brown fox jumped over the lazy dog")
+ data = "The quick brown fox jumped over the lazy dog".split()
for datum in data:
d.append(datum)
d.sync()
@@ -187,13 +192,13 @@
# get the text from the backing source
text = open(source, 'r').read()
- text = string.strip(text)
+ text = text.strip()
if verbose:
print text
print data
- print string.split(text, '\n')
+ print text.split('\n')
- assert string.split(text, '\n') == data
+ assert text.split('\n') == data
# open as a DB again
d = db.DB()
@@ -207,12 +212,13 @@
d.close()
text = open(source, 'r').read()
- text = string.strip(text)
+ text = text.strip()
if verbose:
print text
- print string.split(text, '\n')
+ print text.split('\n')
- assert string.split(text, '\n') == string.split("The quick reddish-brown fox jumped over the comatose dog")
+ assert text.split('\n') == \
+ "The quick reddish-brown fox jumped over the comatose dog".split()
def test03_FixedLength(self):
@@ -248,9 +254,9 @@
#----------------------------------------------------------------------
-def suite():
+def test_suite():
return unittest.makeSuite(SimpleRecnoTestCase)
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')
diff --git a/Lib/bsddb/test/test_thread.py b/Lib/bsddb/test/test_thread.py
index 6231f7d..fb2ba1c 100644
--- a/Lib/bsddb/test/test_thread.py
+++ b/Lib/bsddb/test/test_thread.py
@@ -16,11 +16,10 @@
import unittest
-from test.test_support import verbose
+from test_all import verbose
from bsddb import db, dbutils
-
#----------------------------------------------------------------------
class BaseThreadedTestCase(unittest.TestCase):
@@ -80,7 +79,8 @@
def test01_1WriterMultiReaders(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test01_1WriterMultiReaders..." % self.__class__.__name__
+ print "Running %s.test01_1WriterMultiReaders..." % \
+ self.__class__.__name__
threads = []
for x in range(self.writers):
@@ -112,7 +112,8 @@
for x in range(start, stop):
key = '%04d' % x
- dbutils.DeadlockWrap(d.put, key, self.makeData(key), max_retries=12)
+ 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)
@@ -215,7 +216,8 @@
# create a bunch of records
for x in xrange(start, stop):
key = '%04d' % x
- dbutils.DeadlockWrap(d.put, key, self.makeData(key), max_retries=12)
+ 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)
@@ -284,7 +286,7 @@
class ThreadedTransactionsBase(BaseThreadedTestCase):
- dbopenflags = db.DB_THREAD
+ dbopenflags = db.DB_THREAD | db.DB_AUTO_COMMIT
envflags = (db.DB_THREAD |
db.DB_INIT_MPOOL |
db.DB_INIT_LOCK |
@@ -306,7 +308,8 @@
def test03_ThreadedTransactions(self):
if verbose:
print '\n', '-=' * 30
- print "Running %s.test03_ThreadedTransactions..." % self.__class__.__name__
+ print "Running %s.test03_ThreadedTransactions..." % \
+ self.__class__.__name__
threads = []
for x in range(self.writers):
@@ -430,9 +433,11 @@
while self.doLockDetect:
time.sleep(0.5)
try:
- aborted = self.env.lock_detect(db.DB_LOCK_RANDOM, db.DB_LOCK_CONFLICT)
+ 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
@@ -467,24 +472,24 @@
#----------------------------------------------------------------------
-def suite():
- theSuite = unittest.TestSuite()
+def test_suite():
+ suite = unittest.TestSuite()
if have_threads:
- theSuite.addTest(unittest.makeSuite(BTreeConcurrentDataStore))
- theSuite.addTest(unittest.makeSuite(HashConcurrentDataStore))
- theSuite.addTest(unittest.makeSuite(BTreeSimpleThreaded))
- theSuite.addTest(unittest.makeSuite(HashSimpleThreaded))
- theSuite.addTest(unittest.makeSuite(BTreeThreadedTransactions))
- theSuite.addTest(unittest.makeSuite(HashThreadedTransactions))
- theSuite.addTest(unittest.makeSuite(BTreeThreadedNoWaitTransactions))
- theSuite.addTest(unittest.makeSuite(HashThreadedNoWaitTransactions))
+ suite.addTest(unittest.makeSuite(BTreeConcurrentDataStore))
+ suite.addTest(unittest.makeSuite(HashConcurrentDataStore))
+ suite.addTest(unittest.makeSuite(BTreeSimpleThreaded))
+ suite.addTest(unittest.makeSuite(HashSimpleThreaded))
+ suite.addTest(unittest.makeSuite(BTreeThreadedTransactions))
+ suite.addTest(unittest.makeSuite(HashThreadedTransactions))
+ suite.addTest(unittest.makeSuite(BTreeThreadedNoWaitTransactions))
+ suite.addTest(unittest.makeSuite(HashThreadedNoWaitTransactions))
else:
print "Threads not available, skipping thread tests."
- return theSuite
+ return suite
if __name__ == '__main__':
- unittest.main( defaultTest='suite' )
+ unittest.main(defaultTest='test_suite')