/Lib/test/test_bsddb3.py

http://unladen-swallow.googlecode.com/ · Python · 76 lines · 42 code · 13 blank · 21 comment · 8 complexity · 4ea86178c51ab733f7fbc73902dca614 MD5 · raw file

  1. # Test driver for bsddb package.
  2. """
  3. Run all test cases.
  4. """
  5. import os
  6. import sys
  7. import tempfile
  8. import time
  9. import unittest
  10. from test.test_support import requires, verbose, run_unittest, unlink, rmtree
  11. # When running as a script instead of within the regrtest framework, skip the
  12. # requires test, since it's obvious we want to run them.
  13. if __name__ != '__main__':
  14. requires('bsddb')
  15. verbose = False
  16. if 'verbose' in sys.argv:
  17. verbose = True
  18. sys.argv.remove('verbose')
  19. if 'silent' in sys.argv: # take care of old flag, just in case
  20. verbose = False
  21. sys.argv.remove('silent')
  22. class TimingCheck(unittest.TestCase):
  23. """This class is not a real test. Its purpose is to print a message
  24. periodically when the test runs slowly. This will prevent the buildbots
  25. from timing out on slow machines."""
  26. # How much time in seconds before printing a 'Still working' message.
  27. # Since this is run at most once between each test module, use a smaller
  28. # interval than other tests.
  29. _PRINT_WORKING_MSG_INTERVAL = 4 * 60
  30. # next_time is used as a global variable that survives each instance.
  31. # This is necessary since a new instance will be created for each test.
  32. next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
  33. def testCheckElapsedTime(self):
  34. # Print still working message since these tests can be really slow.
  35. now = time.time()
  36. if self.next_time <= now:
  37. TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
  38. sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
  39. sys.__stdout__.flush()
  40. # For invocation through regrtest
  41. def test_main():
  42. from bsddb import db
  43. from bsddb.test import test_all
  44. test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
  45. 'z-test_bsddb3-%s' %
  46. os.getpid()))
  47. # Please leave this print in, having this show up in the buildbots
  48. # makes diagnosing problems a lot easier.
  49. print >>sys.stderr, db.DB_VERSION_STRING
  50. print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
  51. try:
  52. run_unittest(test_all.suite(module_prefix='bsddb.test.',
  53. timing_check=TimingCheck))
  54. finally:
  55. # The only reason to remove db_home is in case if there is an old
  56. # one lying around. This might be by a different user, so just
  57. # ignore errors. We should always make a unique name now.
  58. try:
  59. test_all.remove_test_path_directory()
  60. except:
  61. pass
  62. if __name__ == '__main__':
  63. test_main()