blob: 5a4258e09bedef4d8f99fa76d62b5c267ed309a2 [file] [log] [blame]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00001# Test driver for bsddb package.
2"""
3Run all test cases.
4"""
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00005import sys
Neal Norwitz41ada162008-01-27 17:13:07 +00006import time
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00007import unittest
Collin Winterc2898c52007-04-25 17:29:52 +00008from test.test_support import requires, verbose, run_unittest, unlink
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00009
Barry Warsaw0a262352002-12-30 20:53:18 +000010# When running as a script instead of within the regrtest framework, skip the
11# requires test, since it's obvious we want to run them.
Collin Winterc2898c52007-04-25 17:29:52 +000012if __name__ != '__main__':
Barry Warsaw0a262352002-12-30 20:53:18 +000013 requires('bsddb')
14
15verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000016if 'verbose' in sys.argv:
Barry Warsaw0a262352002-12-30 20:53:18 +000017 verbose = True
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000018 sys.argv.remove('verbose')
19
20if 'silent' in sys.argv: # take care of old flag, just in case
Barry Warsaw0a262352002-12-30 20:53:18 +000021 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000022 sys.argv.remove('silent')
23
24
Neal Norwitz41ada162008-01-27 17:13:07 +000025class TimingCheck(unittest.TestCase):
26
27 """This class is not a real test. Its purpose is to print a message
28 periodically when the test runs slowly. This will prevent the buildbots
29 from timing out on slow machines."""
30
31 # How much time in seconds before printing a 'Still working' message.
32 # Since this is run at most once between each test module, use a smaller
33 # interval than other tests.
34 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
35
36 # next_time is used as a global variable that survives each instance.
37 # This is necessary since a new instance will be created for each test.
38 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
39
40 def testCheckElapsedTime(self):
41 # Print still working message since these tests can be really slow.
42 now = time.time()
43 if self.next_time <= now:
44 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
45 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
46 sys.__stdout__.flush()
47
48
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000049def suite():
Neal Norwitz62a21122006-01-25 05:21:55 +000050 try:
51 # this is special, it used to segfault the interpreter
52 import bsddb.test.test_1413192
53 except:
Neal Norwitz14361ff2006-01-25 07:20:47 +000054 for f in ['__db.001', '__db.002', '__db.003', 'log.0000000001']:
55 unlink(f)
Neal Norwitz62a21122006-01-25 05:21:55 +000056
Barry Warsaw0a262352002-12-30 20:53:18 +000057 test_modules = [
58 'test_associate',
59 'test_basics',
60 'test_compat',
61 'test_dbobj',
62 'test_dbshelve',
63 'test_dbtables',
64 'test_env_close',
65 'test_get_none',
66 'test_join',
67 'test_lock',
68 'test_misc',
69 'test_queue',
70 'test_recno',
71 'test_thread',
Gregory P. Smithf0547d02006-06-05 17:38:04 +000072 'test_sequence',
Gregory P. Smith372b5832006-06-05 18:48:21 +000073 'test_cursor_pget_bug',
Barry Warsaw0a262352002-12-30 20:53:18 +000074 ]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000075
76 alltests = unittest.TestSuite()
77 for name in test_modules:
78 module = __import__("bsddb.test."+name, globals(), locals(), name)
Barry Warsaw0a262352002-12-30 20:53:18 +000079 #print module,name
80 alltests.addTest(module.test_suite())
Neal Norwitz41ada162008-01-27 17:13:07 +000081 alltests.addTest(unittest.makeSuite(TimingCheck))
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000082 return alltests
83
Barry Warsaw0a262352002-12-30 20:53:18 +000084
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000085# For invocation through regrtest
86def test_main():
Collin Winterc2898c52007-04-25 17:29:52 +000087 run_unittest(suite())
Barry Warsaw0a262352002-12-30 20:53:18 +000088
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000089# For invocation as a script
90if __name__ == '__main__':
91 from bsddb import db
92 print '-=' * 38
93 print db.DB_VERSION_STRING
Barry Warsaw0a262352002-12-30 20:53:18 +000094 print 'bsddb.db.version(): %s' % (db.version(),)
95 print 'bsddb.db.__version__: %s' % db.__version__
96 print 'bsddb.db.cvsid: %s' % db.cvsid
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000097 print 'python version: %s' % sys.version
98 print '-=' * 38
99
Collin Winterc2898c52007-04-25 17:29:52 +0000100 test_main()