blob: 6a277d979805dab589a32f59b2f2669d19d25fae [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
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000017import bsddb.test.test_all
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000018if 'verbose' in sys.argv:
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000019 bsddb.test.test_all.verbose = 1
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
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000023 bsddb.test.test_all.verbose = 0
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 +000051def suite():
Neal Norwitz62a21122006-01-25 05:21:55 +000052 try:
53 # this is special, it used to segfault the interpreter
Martin v. Löwis32ca4422007-08-11 06:13:20 +000054 import bsddb.test.test_1413192
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000055 finally:
56 for f in ['xxx.db','__db.001','__db.002','__db.003','log.0000000001']:
Neal Norwitz14361ff2006-01-25 07:20:47 +000057 unlink(f)
Neal Norwitz62a21122006-01-25 05:21:55 +000058
Barry Warsaw0a262352002-12-30 20:53:18 +000059 test_modules = [
Martin v. Löwiscccc58d2007-08-10 08:36:56 +000060 'test_associate',
61 'test_basics',
62 'test_compat',
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000063 'test_compare',
Martin v. Löwiscccc58d2007-08-10 08:36:56 +000064 'test_dbobj',
Barry Warsaw0a262352002-12-30 20:53:18 +000065 'test_dbshelve',
Martin v. Löwiscccc58d2007-08-10 08:36:56 +000066 'test_dbtables',
67 'test_env_close',
68 'test_get_none',
69 'test_join',
70 'test_lock',
71 'test_misc',
Gregory P. Smith3fd22da2007-08-28 08:05:56 +000072 'test_pickle',
Martin v. Löwiscccc58d2007-08-10 08:36:56 +000073 'test_queue',
74 'test_recno',
75 'test_thread',
76 'test_sequence',
77 'test_cursor_pget_bug',
Barry Warsaw0a262352002-12-30 20:53:18 +000078 ]
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000079
80 alltests = unittest.TestSuite()
81 for name in test_modules:
82 module = __import__("bsddb.test."+name, globals(), locals(), name)
Barry Warsaw0a262352002-12-30 20:53:18 +000083 #print module,name
84 alltests.addTest(module.test_suite())
Christian Heimes412dc9c2008-01-27 18:55:54 +000085 alltests.addTest(unittest.makeSuite(TimingCheck))
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000086 return alltests
87
Barry Warsaw0a262352002-12-30 20:53:18 +000088
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +000089# For invocation through regrtest
90def test_main():
Guido van Rossumd8faa362007-04-27 19:54:29 +000091 run_unittest(suite())
Christian Heimes23daade02008-02-25 12:39:23 +000092 db_home = os.path.join(tempfile.gettempdir(), 'db_home')
93 # The only reason to remove db_home is in case if there is an old
94 # one lying around. This might be by a different user, so just
95 # ignore errors. We should always make a unique name now.
96 try:
97 rmtree(db_home)
98 except:
99 pass
100 rmtree('db_home%d' % os.getpid())
Barry Warsaw0a262352002-12-30 20:53:18 +0000101
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +0000102# For invocation as a script
103if __name__ == '__main__':
104 from bsddb import db
Guido van Rossumbe19ed72007-02-09 05:37:30 +0000105 print('-=' * 38)
106 print(db.DB_VERSION_STRING)
107 print('bsddb.db.version(): %s' % (db.version(),))
108 print('bsddb.db.__version__: %s' % db.__version__)
109 print('bsddb.db.cvsid: %s' % db.cvsid)
110 print('python version: %s' % sys.version)
111 print('-=' * 38)
Martin v. Löwis1c6b1a22002-11-19 17:47:07 +0000112
Guido van Rossumd8faa362007-04-27 19:54:29 +0000113 test_main()