| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  | """Run all test cases.
 | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2006-06-05 17:38:04 +00:00
										 |  |  | try: | 
					
						
							|  |  |  |     # For Pythons w/distutils pybsddb | 
					
						
							|  |  |  |     from bsddb3 import db | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     # For Python 2.3 | 
					
						
							|  |  |  |     from bsddb import db | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-13 20:57:59 +00:00
										 |  |  | try: | 
					
						
							|  |  |  |     from bsddb3 import test_support | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     from test import test_support | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  | 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(): | 
					
						
							|  |  |  |     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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-13 20:57:59 +00:00
										 |  |  | def get_new_path(name) : | 
					
						
							|  |  |  |     get_new_path.mutex.acquire() | 
					
						
							|  |  |  |     try : | 
					
						
							|  |  |  |         import os | 
					
						
							|  |  |  |         path=os.path.join(get_new_path.prefix, | 
					
						
							|  |  |  |                 name+"_"+str(os.getpid())+"_"+str(get_new_path.num)) | 
					
						
							|  |  |  |         get_new_path.num+=1 | 
					
						
							|  |  |  |     finally : | 
					
						
							|  |  |  |         get_new_path.mutex.release() | 
					
						
							|  |  |  |     return path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_new_environment_path() : | 
					
						
							|  |  |  |     path=get_new_path("environment") | 
					
						
							|  |  |  |     import os | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.makedirs(path,mode=0700) | 
					
						
							|  |  |  |     except os.error: | 
					
						
							|  |  |  |         test_support.rmtree(path) | 
					
						
							|  |  |  |         os.makedirs(path) | 
					
						
							|  |  |  |     return path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def get_new_database_path() : | 
					
						
							|  |  |  |     path=get_new_path("database") | 
					
						
							|  |  |  |     import os | 
					
						
							|  |  |  |     if os.path.exists(path) : | 
					
						
							|  |  |  |         os.remove(path) | 
					
						
							|  |  |  |     return path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 13:26:02 +00:00
										 |  |  | # This path can be overriden via "set_test_path_prefix()". | 
					
						
							|  |  |  | import os, os.path | 
					
						
							|  |  |  | get_new_path.prefix=os.path.join(os.sep,"tmp","z-Berkeley_DB") | 
					
						
							| 
									
										
										
										
											2008-05-13 20:57:59 +00:00
										 |  |  | get_new_path.num=0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-27 13:26:02 +00:00
										 |  |  | def get_test_path_prefix() : | 
					
						
							|  |  |  |     return get_new_path.prefix | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def set_test_path_prefix(path) : | 
					
						
							|  |  |  |     get_new_path.prefix=path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def remove_test_path_directory() : | 
					
						
							|  |  |  |     test_support.rmtree(get_new_path.prefix) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-13 20:57:59 +00:00
										 |  |  | try : | 
					
						
							|  |  |  |     import threading | 
					
						
							|  |  |  |     get_new_path.mutex=threading.Lock() | 
					
						
							|  |  |  |     del threading | 
					
						
							|  |  |  | except ImportError: | 
					
						
							|  |  |  |     class Lock(object) : | 
					
						
							|  |  |  |         def acquire(self) : | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |         def release(self) : | 
					
						
							|  |  |  |             pass | 
					
						
							|  |  |  |     get_new_path.mutex=Lock() | 
					
						
							|  |  |  |     del Lock | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  | 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  | def suite(module_prefix='', timing_check=None): | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |     test_modules = [ | 
					
						
							|  |  |  |         'test_associate', | 
					
						
							|  |  |  |         'test_basics', | 
					
						
							| 
									
										
										
										
											2005-06-03 07:03:07 +00:00
										 |  |  |         'test_compare', | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         'test_compat', | 
					
						
							|  |  |  |         'test_cursor_pget_bug', | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |         'test_dbobj', | 
					
						
							|  |  |  |         'test_dbshelve', | 
					
						
							|  |  |  |         'test_dbtables', | 
					
						
							| 
									
										
										
										
											2008-05-13 20:57:59 +00:00
										 |  |  |         'test_distributed_transactions', | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         'test_early_close', | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |         'test_get_none', | 
					
						
							|  |  |  |         'test_join', | 
					
						
							|  |  |  |         'test_lock', | 
					
						
							|  |  |  |         'test_misc', | 
					
						
							| 
									
										
										
										
											2006-04-08 07:10:51 +00:00
										 |  |  |         'test_pickle', | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |         'test_queue', | 
					
						
							|  |  |  |         'test_recno', | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         'test_replication', | 
					
						
							| 
									
										
										
										
											2006-06-05 17:38:04 +00:00
										 |  |  |         'test_sequence', | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         'test_thread', | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |         ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     alltests = unittest.TestSuite() | 
					
						
							|  |  |  |     for name in test_modules: | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         #module = __import__(name) | 
					
						
							|  |  |  |         # Do it this way so that suite may be called externally via | 
					
						
							|  |  |  |         # python's Lib/test/test_bsddb3. | 
					
						
							|  |  |  |         module = __import__(module_prefix+name, globals(), locals(), name) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-16 07:07:06 +00:00
										 |  |  |         alltests.addTest(module.test_suite()) | 
					
						
							| 
									
										
										
										
											2008-05-25 07:14:09 +00:00
										 |  |  |         if timing_check: | 
					
						
							|  |  |  |             alltests.addTest(unittest.makeSuite(timing_check)) | 
					
						
							| 
									
										
										
										
											2002-12-30 20:53:52 +00:00
										 |  |  |     return alltests | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def test_suite(): | 
					
						
							|  |  |  |     suite = unittest.TestSuite() | 
					
						
							|  |  |  |     suite.addTest(unittest.makeSuite(PrintInfoFakeTest)) | 
					
						
							|  |  |  |     return suite | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     print_versions() | 
					
						
							|  |  |  |     unittest.main(defaultTest='suite') |