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 | """ |
Christian Heimes | 23daade0 | 2008-02-25 12:39:23 +0000 | [diff] [blame] | 5 | import os |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 6 | import sys |
Christian Heimes | 23daade0 | 2008-02-25 12:39:23 +0000 | [diff] [blame] | 7 | import tempfile |
Christian Heimes | 412dc9c | 2008-01-27 18:55:54 +0000 | [diff] [blame] | 8 | import time |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 9 | import unittest |
Christian Heimes | 23daade0 | 2008-02-25 12:39:23 +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. |
Guido van Rossum | b053cd8 | 2006-08-24 03:53:23 +0000 | [diff] [blame] | 14 | if __name__ != '__main__': |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 15 | requires('bsddb') |
| 16 | |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 17 | import bsddb.test.test_all |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 18 | if 'verbose' in sys.argv: |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 19 | bsddb.test.test_all.verbose = 1 |
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 |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 23 | bsddb.test.test_all.verbose = 0 |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 24 | sys.argv.remove('silent') |
| 25 | |
| 26 | |
Christian Heimes | 412dc9c | 2008-01-27 18:55:54 +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 |
Martin v. Löwis | 32ca442 | 2007-08-11 06:13:20 +0000 | [diff] [blame] | 54 | import bsddb.test.test_1413192 |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 55 | finally: |
| 56 | for f in ['xxx.db','__db.001','__db.002','__db.003','log.0000000001']: |
Neal Norwitz | 14361ff | 2006-01-25 07:20:47 +0000 | [diff] [blame] | 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 = [ |
Martin v. Löwis | cccc58d | 2007-08-10 08:36:56 +0000 | [diff] [blame] | 60 | 'test_associate', |
| 61 | 'test_basics', |
| 62 | 'test_compat', |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 63 | 'test_compare', |
Martin v. Löwis | cccc58d | 2007-08-10 08:36:56 +0000 | [diff] [blame] | 64 | 'test_dbobj', |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 65 | 'test_dbshelve', |
Martin v. Löwis | cccc58d | 2007-08-10 08:36:56 +0000 | [diff] [blame] | 66 | 'test_dbtables', |
| 67 | 'test_env_close', |
| 68 | 'test_get_none', |
| 69 | 'test_join', |
| 70 | 'test_lock', |
| 71 | 'test_misc', |
Gregory P. Smith | 3fd22da | 2007-08-28 08:05:56 +0000 | [diff] [blame] | 72 | 'test_pickle', |
Martin v. Löwis | cccc58d | 2007-08-10 08:36:56 +0000 | [diff] [blame] | 73 | 'test_queue', |
| 74 | 'test_recno', |
| 75 | 'test_thread', |
| 76 | 'test_sequence', |
| 77 | 'test_cursor_pget_bug', |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 78 | ] |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 79 | |
| 80 | alltests = unittest.TestSuite() |
| 81 | for name in test_modules: |
| 82 | module = __import__("bsddb.test."+name, globals(), locals(), name) |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 83 | #print module,name |
| 84 | alltests.addTest(module.test_suite()) |
Christian Heimes | 412dc9c | 2008-01-27 18:55:54 +0000 | [diff] [blame] | 85 | alltests.addTest(unittest.makeSuite(TimingCheck)) |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 86 | return alltests |
| 87 | |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 88 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 89 | # For invocation through regrtest |
| 90 | def test_main(): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 91 | run_unittest(suite()) |
Christian Heimes | 23daade0 | 2008-02-25 12:39:23 +0000 | [diff] [blame] | 92 | 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 Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 101 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 102 | # For invocation as a script |
| 103 | if __name__ == '__main__': |
| 104 | from bsddb import db |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 105 | 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öwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 112 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 113 | test_main() |