blob: b290a6edb53ebb5c1518f75e61e95d660f9a676b [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
R. David Murray3db8a342009-03-30 23:05:48 +000010from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
11 import_module)
12
13#Skip test if bsddb cannot import _bsddb.
14import_module('bsddb')
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000015
Barry Warsaw0a262352002-12-30 20:53:18 +000016# When running as a script instead of within the regrtest framework, skip the
17# requires test, since it's obvious we want to run them.
Collin Winterc2898c52007-04-25 17:29:52 +000018if __name__ != '__main__':
Barry Warsaw0a262352002-12-30 20:53:18 +000019 requires('bsddb')
20
21verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000022if 'verbose' in sys.argv:
Barry Warsaw0a262352002-12-30 20:53:18 +000023 verbose = True
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000024 sys.argv.remove('verbose')
25
26if 'silent' in sys.argv: # take care of old flag, just in case
Barry Warsaw0a262352002-12-30 20:53:18 +000027 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000028 sys.argv.remove('silent')
29
30
Neal Norwitz41ada162008-01-27 17:13:07 +000031class TimingCheck(unittest.TestCase):
32
33 """This class is not a real test. Its purpose is to print a message
34 periodically when the test runs slowly. This will prevent the buildbots
35 from timing out on slow machines."""
36
37 # How much time in seconds before printing a 'Still working' message.
38 # Since this is run at most once between each test module, use a smaller
39 # interval than other tests.
40 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
41
42 # next_time is used as a global variable that survives each instance.
43 # This is necessary since a new instance will be created for each test.
44 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
45
46 def testCheckElapsedTime(self):
47 # Print still working message since these tests can be really slow.
48 now = time.time()
49 if self.next_time <= now:
50 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
51 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
52 sys.__stdout__.flush()
53
54
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000055# For invocation through regrtest
56def test_main():
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000057 from bsddb import db
Gregory P. Smith81072902008-05-25 07:14:09 +000058 from bsddb.test import test_all
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000059 test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
60 'z-test_bsddb3-%s' %
61 os.getpid()))
Gregory P. Smith81072902008-05-25 07:14:09 +000062 # Please leave this print in, having this show up in the buildbots
63 # makes diagnosing problems a lot easier.
64 print >>sys.stderr, db.DB_VERSION_STRING
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000065 print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
Gregory P. Smith81072902008-05-25 07:14:09 +000066 try:
67 run_unittest(test_all.suite(module_prefix='bsddb.test.',
68 timing_check=TimingCheck))
69 finally:
70 # The only reason to remove db_home is in case if there is an old
71 # one lying around. This might be by a different user, so just
72 # ignore errors. We should always make a unique name now.
73 try:
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000074 test_all.remove_test_path_directory()
Gregory P. Smith81072902008-05-25 07:14:09 +000075 except:
76 pass
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000077
Gregory P. Smith81072902008-05-25 07:14:09 +000078
79if __name__ == '__main__':
Collin Winterc2898c52007-04-25 17:29:52 +000080 test_main()