Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 1 | # Test driver for bsddb package. |
| 2 | """ |
| 3 | Run all test cases. |
| 4 | """ |
Neal Norwitz | 6057b2e | 2008-02-24 18:47:03 +0000 | [diff] [blame^] | 5 | import os |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 6 | import sys |
Neal Norwitz | 6057b2e | 2008-02-24 18:47:03 +0000 | [diff] [blame^] | 7 | import tempfile |
Neal Norwitz | 41ada16 | 2008-01-27 17:13:07 +0000 | [diff] [blame] | 8 | import time |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 9 | import unittest |
Neal Norwitz | 6057b2e | 2008-02-24 18:47:03 +0000 | [diff] [blame^] | 10 | from test.test_support import requires, verbose, run_unittest, unlink, rmtree |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 11 | |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 12 | # 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. |
Collin Winter | c2898c5 | 2007-04-25 17:29:52 +0000 | [diff] [blame] | 14 | if __name__ != '__main__': |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 15 | requires('bsddb') |
| 16 | |
| 17 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 18 | if 'verbose' in sys.argv: |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 19 | verbose = True |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 20 | sys.argv.remove('verbose') |
| 21 | |
| 22 | if 'silent' in sys.argv: # take care of old flag, just in case |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 23 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 24 | sys.argv.remove('silent') |
| 25 | |
| 26 | |
Neal Norwitz | 41ada16 | 2008-01-27 17:13:07 +0000 | [diff] [blame] | 27 | class 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öwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 51 | def suite(): |
Neal Norwitz | 62a2112 | 2006-01-25 05:21:55 +0000 | [diff] [blame] | 52 | try: |
| 53 | # this is special, it used to segfault the interpreter |
| 54 | import bsddb.test.test_1413192 |
| 55 | except: |
Neal Norwitz | 14361ff | 2006-01-25 07:20:47 +0000 | [diff] [blame] | 56 | for f in ['__db.001', '__db.002', '__db.003', 'log.0000000001']: |
| 57 | unlink(f) |
Neal Norwitz | 62a2112 | 2006-01-25 05:21:55 +0000 | [diff] [blame] | 58 | |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 59 | test_modules = [ |
| 60 | 'test_associate', |
| 61 | 'test_basics', |
| 62 | 'test_compat', |
| 63 | 'test_dbobj', |
| 64 | 'test_dbshelve', |
| 65 | 'test_dbtables', |
| 66 | 'test_env_close', |
| 67 | 'test_get_none', |
| 68 | 'test_join', |
| 69 | 'test_lock', |
| 70 | 'test_misc', |
| 71 | 'test_queue', |
| 72 | 'test_recno', |
| 73 | 'test_thread', |
Gregory P. Smith | f0547d0 | 2006-06-05 17:38:04 +0000 | [diff] [blame] | 74 | 'test_sequence', |
Gregory P. Smith | 372b583 | 2006-06-05 18:48:21 +0000 | [diff] [blame] | 75 | 'test_cursor_pget_bug', |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 76 | ] |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 77 | |
| 78 | alltests = unittest.TestSuite() |
| 79 | for name in test_modules: |
| 80 | module = __import__("bsddb.test."+name, globals(), locals(), name) |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 81 | #print module,name |
| 82 | alltests.addTest(module.test_suite()) |
Neal Norwitz | 41ada16 | 2008-01-27 17:13:07 +0000 | [diff] [blame] | 83 | alltests.addTest(unittest.makeSuite(TimingCheck)) |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 84 | return alltests |
| 85 | |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 86 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 87 | # For invocation through regrtest |
| 88 | def test_main(): |
Collin Winter | c2898c5 | 2007-04-25 17:29:52 +0000 | [diff] [blame] | 89 | run_unittest(suite()) |
Neal Norwitz | 6057b2e | 2008-02-24 18:47:03 +0000 | [diff] [blame^] | 90 | db_home = os.path.join(tempfile.gettempdir(), 'db_home') |
| 91 | # The only reason to remove db_home is in case if there is an old |
| 92 | # one lying around. This might be by a different user, so just |
| 93 | # ignore errors. We should always make a unique name now. |
| 94 | try: |
| 95 | rmtree(db_home) |
| 96 | except: |
| 97 | pass |
| 98 | rmtree('db_home%d' % os.getpid()) |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 99 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 100 | # For invocation as a script |
| 101 | if __name__ == '__main__': |
| 102 | from bsddb import db |
| 103 | print '-=' * 38 |
| 104 | print db.DB_VERSION_STRING |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 105 | print 'bsddb.db.version(): %s' % (db.version(),) |
| 106 | print 'bsddb.db.__version__: %s' % db.__version__ |
| 107 | print 'bsddb.db.cvsid: %s' % db.cvsid |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 108 | print 'python version: %s' % sys.version |
| 109 | print '-=' * 38 |
| 110 | |
Collin Winter | c2898c5 | 2007-04-25 17:29:52 +0000 | [diff] [blame] | 111 | test_main() |