home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_298 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.5 KB  |  72 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import pickle
  6.  
  7. try:
  8.     import cPickle
  9. except ImportError:
  10.     cPickle = None
  11.  
  12. import unittest
  13. from test_all import db, test_support, get_new_environment_path, get_new_database_path
  14.  
  15. class pickleTestCase(unittest.TestCase):
  16.     db_name = 'test-dbobj.db'
  17.     
  18.     def setUp(self):
  19.         self.homeDir = get_new_environment_path()
  20.  
  21.     
  22.     def tearDown(self):
  23.         if hasattr(self, 'db'):
  24.             del self.db
  25.         
  26.         if hasattr(self, 'env'):
  27.             del self.env
  28.         
  29.         test_support.rmtree(self.homeDir)
  30.  
  31.     
  32.     def _base_test_pickle_DBError(self, pickle):
  33.         self.env = db.DBEnv()
  34.         self.env.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL)
  35.         self.db = db.DB(self.env)
  36.         self.db.open(self.db_name, db.DB_HASH, db.DB_CREATE)
  37.         self.db.put('spam', 'eggs')
  38.         self.assertEqual(self.db['spam'], 'eggs')
  39.         
  40.         try:
  41.             self.db.put('spam', 'ham', flags = db.DB_NOOVERWRITE)
  42.         except db.DBError:
  43.             egg = None
  44.             pickledEgg = pickle.dumps(egg)
  45.             rottenEgg = pickle.loads(pickledEgg)
  46.             if rottenEgg.args != egg.args or type(rottenEgg) != type(egg):
  47.                 raise Exception, (rottenEgg, '!=', egg)
  48.             type(rottenEgg) != type(egg)
  49.  
  50.         raise Exception, "where's my DBError exception?!?"
  51.         self.db.close()
  52.         self.env.close()
  53.  
  54.     
  55.     def test01_pickle_DBError(self):
  56.         self._base_test_pickle_DBError(pickle = pickle)
  57.  
  58.     if cPickle:
  59.         
  60.         def test02_cPickle_DBError(self):
  61.             self._base_test_pickle_DBError(pickle = cPickle)
  62.  
  63.     
  64.  
  65.  
  66. def test_suite():
  67.     return unittest.makeSuite(pickleTestCase)
  68.  
  69. if __name__ == '__main__':
  70.     unittest.main(defaultTest = 'test_suite')
  71.  
  72.