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 |
Ezio Melotti | 8d3f130 | 2010-02-02 15:57:45 +0000 | [diff] [blame] | 10 | from test.test_support import requires, run_unittest, import_module |
R. David Murray | 3db8a34 | 2009-03-30 23:05:48 +0000 | [diff] [blame] | 11 | |
R. David Murray | 597ebab | 2009-03-31 18:32:17 +0000 | [diff] [blame] | 12 | # Skip test if _bsddb module was not built. |
| 13 | import_module('_bsddb') |
Ezio Melotti | 5d62cfe | 2010-02-02 08:37:35 +0000 | [diff] [blame] | 14 | # Silence Py3k warning |
| 15 | import_module('bsddb', deprecated=True) |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 16 | |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 17 | # When running as a script instead of within the regrtest framework, skip the |
| 18 | # requires test, since it's obvious we want to run them. |
Collin Winter | c2898c5 | 2007-04-25 17:29:52 +0000 | [diff] [blame] | 19 | if __name__ != '__main__': |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 20 | requires('bsddb') |
| 21 | |
| 22 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 23 | if 'verbose' in sys.argv: |
Barry Warsaw | 0a26235 | 2002-12-30 20:53:18 +0000 | [diff] [blame] | 24 | verbose = True |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 25 | sys.argv.remove('verbose') |
| 26 | |
| 27 | 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] | 28 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 29 | sys.argv.remove('silent') |
| 30 | |
| 31 | |
Neal Norwitz | 41ada16 | 2008-01-27 17:13:07 +0000 | [diff] [blame] | 32 | class TimingCheck(unittest.TestCase): |
| 33 | |
| 34 | """This class is not a real test. Its purpose is to print a message |
| 35 | periodically when the test runs slowly. This will prevent the buildbots |
| 36 | from timing out on slow machines.""" |
| 37 | |
| 38 | # How much time in seconds before printing a 'Still working' message. |
| 39 | # Since this is run at most once between each test module, use a smaller |
| 40 | # interval than other tests. |
| 41 | _PRINT_WORKING_MSG_INTERVAL = 4 * 60 |
| 42 | |
| 43 | # next_time is used as a global variable that survives each instance. |
| 44 | # This is necessary since a new instance will be created for each test. |
| 45 | next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL |
| 46 | |
| 47 | def testCheckElapsedTime(self): |
| 48 | # Print still working message since these tests can be really slow. |
| 49 | now = time.time() |
| 50 | if self.next_time <= now: |
| 51 | TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL |
| 52 | sys.__stdout__.write(' test_bsddb3 still working, be patient...\n') |
| 53 | sys.__stdout__.flush() |
| 54 | |
| 55 | |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 56 | # For invocation through regrtest |
| 57 | def test_main(): |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 58 | from bsddb import db |
Gregory P. Smith | 8107290 | 2008-05-25 07:14:09 +0000 | [diff] [blame] | 59 | from bsddb.test import test_all |
Jesus Cea | dbd2f6d | 2008-05-27 13:26:02 +0000 | [diff] [blame] | 60 | test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(), |
| 61 | 'z-test_bsddb3-%s' % |
| 62 | os.getpid())) |
Gregory P. Smith | 8107290 | 2008-05-25 07:14:09 +0000 | [diff] [blame] | 63 | # Please leave this print in, having this show up in the buildbots |
| 64 | # makes diagnosing problems a lot easier. |
| 65 | print >>sys.stderr, db.DB_VERSION_STRING |
Jesus Cea | dbd2f6d | 2008-05-27 13:26:02 +0000 | [diff] [blame] | 66 | print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix() |
Gregory P. Smith | 8107290 | 2008-05-25 07:14:09 +0000 | [diff] [blame] | 67 | try: |
| 68 | run_unittest(test_all.suite(module_prefix='bsddb.test.', |
| 69 | timing_check=TimingCheck)) |
| 70 | finally: |
| 71 | # The only reason to remove db_home is in case if there is an old |
| 72 | # one lying around. This might be by a different user, so just |
| 73 | # ignore errors. We should always make a unique name now. |
| 74 | try: |
Jesus Cea | dbd2f6d | 2008-05-27 13:26:02 +0000 | [diff] [blame] | 75 | test_all.remove_test_path_directory() |
Gregory P. Smith | 8107290 | 2008-05-25 07:14:09 +0000 | [diff] [blame] | 76 | except: |
| 77 | pass |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 78 | |
Gregory P. Smith | 8107290 | 2008-05-25 07:14:09 +0000 | [diff] [blame] | 79 | |
| 80 | if __name__ == '__main__': |
Collin Winter | c2898c5 | 2007-04-25 17:29:52 +0000 | [diff] [blame] | 81 | test_main() |