blob: 41d0e219dee2b074c156bc5c43098db92c4a5173 [file] [log] [blame]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00001# Test driver for bsddb package.
2"""
3Run all test cases.
4"""
Christian Heimes23daade02008-02-25 12:39:23 +00005import os
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00006import sys
Christian Heimes23daade02008-02-25 12:39:23 +00007import tempfile
Christian Heimes412dc9c2008-01-27 18:55:54 +00008import time
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +00009import unittest
Benjamin Petersonee8712c2008-05-20 21:35:26 +000010from 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.
Guido van Rossumb053cd82006-08-24 03:53:23 +000014if __name__ != '__main__':
Barry Warsaw0a262352002-12-30 20:53:18 +000015 requires('bsddb')
16
Jesus Cead098ff22008-09-02 00:06:22 +000017verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000018if 'verbose' in sys.argv:
Jesus Cead098ff22008-09-02 00:06:22 +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
Jesus Cead098ff22008-09-02 00:06:22 +000023 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000024 sys.argv.remove('silent')
25
26
Christian Heimes412dc9c2008-01-27 18:55:54 +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 +000051# For invocation through regrtest
52def test_main():
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000053 from bsddb import db
Jesus Cead098ff22008-09-02 00:06:22 +000054 from bsddb.test import test_all
55 test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
56 'z-test_bsddb3-%s' %
57 os.getpid()))
58 # Please leave this print in, having this show up in the buildbots
59 # makes diagnosing problems a lot easier.
Jesus Cead6a6d3f2008-09-03 20:23:47 +000060 # The decode is used to workaround this:
61 # http://mail.python.org/pipermail/python-3000/2008-September/014709.html
62 print(db.DB_VERSION_STRING.decode("iso8859-1"), file=sys.stderr)
Jesus Cead098ff22008-09-02 00:06:22 +000063 print('Test path prefix: ', test_all.get_test_path_prefix(), file=sys.stderr)
64 try:
65 run_unittest(test_all.suite(module_prefix='bsddb.test.',
66 timing_check=TimingCheck))
67 finally:
68 # The only reason to remove db_home is in case if there is an old
69 # one lying around. This might be by a different user, so just
70 # ignore errors. We should always make a unique name now.
71 try:
72 test_all.remove_test_path_directory()
73 except:
74 pass
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000075
Jesus Cead098ff22008-09-02 00:06:22 +000076
77if __name__ == '__main__':
Guido van Rossumd8faa362007-04-27 19:54:29 +000078 test_main()