0001 """Miscellaneous bsddb module test cases 0002 """ 0003 0004 import os 0005 import sys 0006 import unittest 0007 0008 try: 0009 # For Pythons w/distutils pybsddb 0010 from bsddb3 import db, dbshelve 0011 except ImportError: 0012 # For Python 2.3 0013 from bsddb import db, dbshelve 0014 0015 #---------------------------------------------------------------------- 0016 0017 class MiscTestCase(unittest.TestCase): 0018 def setUp(self): 0019 self.filename = self.__class__.__name__ + '.db' 0020 homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home') 0021 self.homeDir = homeDir 0022 try: 0023 os.mkdir(homeDir) 0024 except OSError: 0025 pass 0026 0027 def tearDown(self): 0028 try: 0029 os.remove(self.filename) 0030 except OSError: 0031 pass 0032 import glob 0033 files = glob.glob(os.path.join(self.homeDir, '*')) 0034 for file in files: 0035 os.remove(file) 0036 0037 def test01_badpointer(self): 0038 dbs = dbshelve.open(self.filename) 0039 dbs.close() 0040 self.assertRaises(db.DBError, dbs.get, "foo") 0041 0042 def test02_db_home(self): 0043 env = db.DBEnv() 0044 # check for crash fixed when db_home is used before open() 0045 assert env.db_home is None 0046 env.open(self.homeDir, db.DB_CREATE) 0047 assert self.homeDir == env.db_home 0048 0049 0050 #---------------------------------------------------------------------- 0051 0052 0053 def test_suite(): 0054 return unittest.makeSuite(MiscTestCase) 0055 0056 0057 if __name__ == '__main__': 0058 unittest.main(defaultTest='test_suite') 0059
Generated by PyXR 0.9.4