blob: b9726f1758bab9873a60a306677d4a3ff66cd293 [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
R. David Murray597ebab2009-03-31 18:32:17 +000013# Skip test if _bsddb module was not built.
14import_module('_bsddb')
Ezio Melotti5d62cfe2010-02-02 08:37:35 +000015# Silence Py3k warning
16import_module('bsddb', deprecated=True)
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000017
Barry Warsaw0a262352002-12-30 20:53:18 +000018# When running as a script instead of within the regrtest framework, skip the
19# requires test, since it's obvious we want to run them.
Collin Winterc2898c52007-04-25 17:29:52 +000020if __name__ != '__main__':
Barry Warsaw0a262352002-12-30 20:53:18 +000021 requires('bsddb')
22
23verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000024if 'verbose' in sys.argv:
Barry Warsaw0a262352002-12-30 20:53:18 +000025 verbose = True
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000026 sys.argv.remove('verbose')
27
28if 'silent' in sys.argv: # take care of old flag, just in case
Barry Warsaw0a262352002-12-30 20:53:18 +000029 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000030 sys.argv.remove('silent')
31
32
Neal Norwitz41ada162008-01-27 17:13:07 +000033class TimingCheck(unittest.TestCase):
34
35 """This class is not a real test. Its purpose is to print a message
36 periodically when the test runs slowly. This will prevent the buildbots
37 from timing out on slow machines."""
38
39 # How much time in seconds before printing a 'Still working' message.
40 # Since this is run at most once between each test module, use a smaller
41 # interval than other tests.
42 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
43
44 # next_time is used as a global variable that survives each instance.
45 # This is necessary since a new instance will be created for each test.
46 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
47
48 def testCheckElapsedTime(self):
49 # Print still working message since these tests can be really slow.
50 now = time.time()
51 if self.next_time <= now:
52 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
53 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
54 sys.__stdout__.flush()
55
56
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000057# For invocation through regrtest
58def test_main():
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000059 from bsddb import db
Gregory P. Smith81072902008-05-25 07:14:09 +000060 from bsddb.test import test_all
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000061 test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
62 'z-test_bsddb3-%s' %
63 os.getpid()))
Gregory P. Smith81072902008-05-25 07:14:09 +000064 # Please leave this print in, having this show up in the buildbots
65 # makes diagnosing problems a lot easier.
66 print >>sys.stderr, db.DB_VERSION_STRING
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000067 print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
Gregory P. Smith81072902008-05-25 07:14:09 +000068 try:
69 run_unittest(test_all.suite(module_prefix='bsddb.test.',
70 timing_check=TimingCheck))
71 finally:
72 # The only reason to remove db_home is in case if there is an old
73 # one lying around. This might be by a different user, so just
74 # ignore errors. We should always make a unique name now.
75 try:
Jesus Ceadbd2f6d2008-05-27 13:26:02 +000076 test_all.remove_test_path_directory()
Gregory P. Smith81072902008-05-25 07:14:09 +000077 except:
78 pass
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000079
Gregory P. Smith81072902008-05-25 07:14:09 +000080
81if __name__ == '__main__':
Collin Winterc2898c52007-04-25 17:29:52 +000082 test_main()