blob: 9079b0ee6b1e1460ee4d400bff65ac11e6fc50d3 [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.
Jesus Cead098ff22008-09-02 00:06:22 +000014verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000015if 'verbose' in sys.argv:
Jesus Cead098ff22008-09-02 00:06:22 +000016 verbose = True
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000017 sys.argv.remove('verbose')
18
19if 'silent' in sys.argv: # take care of old flag, just in case
Jesus Cead098ff22008-09-02 00:06:22 +000020 verbose = False
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000021 sys.argv.remove('silent')
22
23
Christian Heimes412dc9c2008-01-27 18:55:54 +000024class TimingCheck(unittest.TestCase):
25
26 """This class is not a real test. Its purpose is to print a message
27 periodically when the test runs slowly. This will prevent the buildbots
28 from timing out on slow machines."""
29
30 # How much time in seconds before printing a 'Still working' message.
31 # Since this is run at most once between each test module, use a smaller
32 # interval than other tests.
33 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
34
35 # next_time is used as a global variable that survives each instance.
36 # This is necessary since a new instance will be created for each test.
37 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
38
39 def testCheckElapsedTime(self):
40 # Print still working message since these tests can be really slow.
41 now = time.time()
42 if self.next_time <= now:
43 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
44 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
45 sys.__stdout__.flush()
46
47
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000048# For invocation through regrtest
49def test_main():
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000050 from bsddb import db
Jesus Cead098ff22008-09-02 00:06:22 +000051 from bsddb.test import test_all
Jesus Ceaa64072f2008-09-03 22:07:33 +000052
53 # This must be improved...
54 test_all.do_proxy_db_py3k(True)
55
Jesus Cead098ff22008-09-02 00:06:22 +000056 test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
57 'z-test_bsddb3-%s' %
58 os.getpid()))
59 # Please leave this print in, having this show up in the buildbots
60 # makes diagnosing problems a lot easier.
Jesus Cead6a6d3f2008-09-03 20:23:47 +000061 # The decode is used to workaround this:
62 # http://mail.python.org/pipermail/python-3000/2008-September/014709.html
63 print(db.DB_VERSION_STRING.decode("iso8859-1"), file=sys.stderr)
Jesus Cead098ff22008-09-02 00:06:22 +000064 print('Test path prefix: ', test_all.get_test_path_prefix(), file=sys.stderr)
65 try:
66 run_unittest(test_all.suite(module_prefix='bsddb.test.',
67 timing_check=TimingCheck))
68 finally:
69 # The only reason to remove db_home is in case if there is an old
70 # one lying around. This might be by a different user, so just
71 # ignore errors. We should always make a unique name now.
72 try:
73 test_all.remove_test_path_directory()
74 except:
75 pass
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000076
Jesus Ceaa64072f2008-09-03 22:07:33 +000077 # This must be improved...
78 test_all.do_proxy_db_py3k(False)
79
Jesus Cead098ff22008-09-02 00:06:22 +000080
81if __name__ == '__main__':
Guido van Rossumd8faa362007-04-27 19:54:29 +000082 test_main()