blob: a4d22941adfd508e1465adae2e0d666ad5ccf592 [file] [log] [blame]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00001# Test driver for bsddb package.
2"""
3Run all test cases.
4"""
Neal Norwitz6057b2e2008-02-24 18:47:03 +00005import os
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00006import sys
Neal Norwitz6057b2e2008-02-24 18:47:03 +00007import tempfile
Neal Norwitz41ada162008-01-27 17:13:07 +00008import time
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00009import unittest
Neal Norwitz6057b2e2008-02-24 18:47:03 +000010from test.test_support import requires, verbose, run_unittest, unlink, rmtree
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000011
Barry Warsaw0a262352002-12-30 20:53:18 +000012# When running as a script instead of within the regrtest framework, skip the
13# requires test, since it's obvious we want to run them.
Collin Winterc2898c52007-04-25 17:29:52 +000014if __name__ != '__main__':
Barry Warsaw0a262352002-12-30 20:53:18 +000015 requires('bsddb')
16
17verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000018if 'verbose' in sys.argv:
Barry Warsaw0a262352002-12-30 20:53:18 +000019 verbose = True
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000020 sys.argv.remove('verbose')
21
22if 'silent' in sys.argv: # take care of old flag, just in case
Barry Warsaw0a262352002-12-30 20:53:18 +000023 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000024 sys.argv.remove('silent')
25
26
Neal Norwitz41ada162008-01-27 17:13:07 +000027class TimingCheck(unittest.TestCase):
28
29 """This class is not a real test. Its purpose is to print a message
30 periodically when the test runs slowly. This will prevent the buildbots
31 from timing out on slow machines."""
32
33 # How much time in seconds before printing a 'Still working' message.
34 # Since this is run at most once between each test module, use a smaller
35 # interval than other tests.
36 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
37
38 # next_time is used as a global variable that survives each instance.
39 # This is necessary since a new instance will be created for each test.
40 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
41
42 def testCheckElapsedTime(self):
43 # Print still working message since these tests can be really slow.
44 now = time.time()
45 if self.next_time <= now:
46 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
47 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
48 sys.__stdout__.flush()
49
50
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000051def suite():
Barry Warsaw0a262352002-12-30 20:53:18 +000052 test_modules = [
53 'test_associate',
54 'test_basics',
Gregory P. Smithee365b92008-05-14 04:27:01 +000055 'test_compare',
Barry Warsaw0a262352002-12-30 20:53:18 +000056 'test_compat',
Gregory P. Smithee365b92008-05-14 04:27:01 +000057 'test_cursor_pget_bug',
Barry Warsaw0a262352002-12-30 20:53:18 +000058 'test_dbobj',
59 'test_dbshelve',
60 'test_dbtables',
Gregory P. Smithee365b92008-05-14 04:27:01 +000061 'test_distributed_transactions',
62 'test_early_close',
Barry Warsaw0a262352002-12-30 20:53:18 +000063 'test_get_none',
64 'test_join',
65 'test_lock',
66 'test_misc',
Gregory P. Smithee365b92008-05-14 04:27:01 +000067 'test_pickle',
Barry Warsaw0a262352002-12-30 20:53:18 +000068 'test_queue',
69 'test_recno',
Gregory P. Smithee365b92008-05-14 04:27:01 +000070 'test_replication',
Gregory P. Smithf0547d02006-06-05 17:38:04 +000071 'test_sequence',
Gregory P. Smithee365b92008-05-14 04:27:01 +000072 'test_thread',
Barry Warsaw0a262352002-12-30 20:53:18 +000073 ]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000074
75 alltests = unittest.TestSuite()
76 for name in test_modules:
77 module = __import__("bsddb.test."+name, globals(), locals(), name)
Barry Warsaw0a262352002-12-30 20:53:18 +000078 #print module,name
79 alltests.addTest(module.test_suite())
Neal Norwitz41ada162008-01-27 17:13:07 +000080 alltests.addTest(unittest.makeSuite(TimingCheck))
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000081 return alltests
82
Barry Warsaw0a262352002-12-30 20:53:18 +000083
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000084# For invocation through regrtest
85def test_main():
Collin Winterc2898c52007-04-25 17:29:52 +000086 run_unittest(suite())
Neal Norwitz6057b2e2008-02-24 18:47:03 +000087 db_home = os.path.join(tempfile.gettempdir(), 'db_home')
88 # The only reason to remove db_home is in case if there is an old
89 # one lying around. This might be by a different user, so just
90 # ignore errors. We should always make a unique name now.
91 try:
92 rmtree(db_home)
93 except:
94 pass
95 rmtree('db_home%d' % os.getpid())
Barry Warsaw0a262352002-12-30 20:53:18 +000096
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000097# For invocation as a script
98if __name__ == '__main__':
99 from bsddb import db
100 print '-=' * 38
101 print db.DB_VERSION_STRING
Barry Warsaw0a262352002-12-30 20:53:18 +0000102 print 'bsddb.db.version(): %s' % (db.version(),)
103 print 'bsddb.db.__version__: %s' % db.__version__
104 print 'bsddb.db.cvsid: %s' % db.cvsid
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +0000105 print 'python version: %s' % sys.version
106 print '-=' * 38
107
Collin Winterc2898c52007-04-25 17:29:52 +0000108 test_main()