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 |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 10 | from 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. |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 14 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 15 | if 'verbose' in sys.argv: |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 16 | verbose = True |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 17 | sys.argv.remove('verbose') |
| 18 | |
| 19 | if 'silent' in sys.argv: # take care of old flag, just in case |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 20 | verbose = False |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 21 | sys.argv.remove('silent') |
| 22 | |
| 23 | |
Christian Heimes | 412dc9c | 2008-01-27 18:55:54 +0000 | [diff] [blame] | 24 | class 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öwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 48 | # For invocation through regrtest |
| 49 | def test_main(): |
Martin v. Löwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 50 | from bsddb import db |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 51 | from bsddb.test import test_all |
Jesus Cea | a64072f | 2008-09-03 22:07:33 +0000 | [diff] [blame] | 52 | |
| 53 | # This must be improved... |
| 54 | test_all.do_proxy_db_py3k(True) |
| 55 | |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 56 | 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 Cea | d6a6d3f | 2008-09-03 20:23:47 +0000 | [diff] [blame] | 61 | # 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 Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 64 | 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öwis | 1c6b1a2 | 2002-11-19 17:47:07 +0000 | [diff] [blame] | 76 | |
Jesus Cea | a64072f | 2008-09-03 22:07:33 +0000 | [diff] [blame] | 77 | # This must be improved... |
| 78 | test_all.do_proxy_db_py3k(False) |
| 79 | |
Jesus Cea | d098ff2 | 2008-09-02 00:06:22 +0000 | [diff] [blame] | 80 | |
| 81 | if __name__ == '__main__': |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 82 | test_main() |