home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 June / PCWorld_2005-06_cd.bin / software / vyzkuste / firewally / firewally.exe / framework-2.3.exe / test_misc.py < prev    next >
Text File  |  2003-12-30  |  1KB  |  59 lines

  1. """Miscellaneous bsddb module test cases
  2. """
  3.  
  4. import os
  5. import sys
  6. import unittest
  7.  
  8. try:
  9.     # For Python 2.3
  10.     from bsddb import db, dbshelve
  11. except ImportError:
  12.     # For earlier Pythons w/distutils pybsddb
  13.     from bsddb3 import db, dbshelve
  14.  
  15. #----------------------------------------------------------------------
  16.  
  17. class MiscTestCase(unittest.TestCase):
  18.     def setUp(self):
  19.         self.filename = self.__class__.__name__ + '.db'
  20.         homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
  21.         self.homeDir = homeDir
  22.         try:
  23.             os.mkdir(homeDir)
  24.         except OSError:
  25.             pass
  26.  
  27.     def tearDown(self):
  28.         try:
  29.             os.remove(self.filename)
  30.         except OSError:
  31.             pass
  32.         import glob
  33.         files = glob.glob(os.path.join(self.homeDir, '*'))
  34.         for file in files:
  35.             os.remove(file)
  36.  
  37.     def test01_badpointer(self):
  38.         dbs = dbshelve.open(self.filename)
  39.         dbs.close()
  40.         self.assertRaises(db.DBError, dbs.get, "foo")
  41.  
  42.     def test02_db_home(self):
  43.         env = db.DBEnv()
  44.         # check for crash fixed when db_home is used before open()
  45.         assert env.db_home is None
  46.         env.open(self.homeDir, db.DB_CREATE)
  47.         assert self.homeDir == env.db_home
  48.  
  49.  
  50. #----------------------------------------------------------------------
  51.  
  52.  
  53. def test_suite():
  54.     return unittest.makeSuite(MiscTestCase)
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     unittest.main(defaultTest='test_suite')
  59.