test_bsddb3.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, run_unittest, import_module
  11. # Skip test if _bsddb module was not built.
  12. import_module('_bsddb')
  13. # Silence Py3k warning
  14. import_module('bsddb', deprecated=True)
  15. # When running as a script instead of within the regrtest framework, skip the
  16. # requires test, since it's obvious we want to run them.
  17. if __name__ != '__main__':
  18. requires('bsddb')
  19. verbose = False
  20. if 'verbose' in sys.argv:
  21. verbose = True
  22. sys.argv.remove('verbose')
  23. if 'silent' in sys.argv: # take care of old flag, just in case
  24. verbose = False
  25. sys.argv.remove('silent')
  26. class TimingCheck(unittest.TestCase):
  27. """This class is not a real test. Its purpose is to print a message
  28. periodically when the test runs slowly. This will prevent the buildbots
  29. from timing out on slow machines."""
  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. # next_time is used as a global variable that survives each instance.
  35. # This is necessary since a new instance will be created for each test.
  36. next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
  37. def testCheckElapsedTime(self):
  38. # Print still working message since these tests can be really slow.
  39. now = time.time()
  40. if self.next_time <= now:
  41. TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
  42. sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
  43. sys.__stdout__.flush()
  44. # For invocation through regrtest
  45. def test_main():
  46. from bsddb import db
  47. from bsddb.test import test_all
  48. test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
  49. 'z-test_bsddb3-%s' %
  50. os.getpid()))
  51. # Please leave this print in, having this show up in the buildbots
  52. # makes diagnosing problems a lot easier.
  53. print >>sys.stderr, db.DB_VERSION_STRING
  54. print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
  55. try:
  56. run_unittest(test_all.suite(module_prefix='bsddb.test.',
  57. timing_check=TimingCheck))
  58. finally:
  59. # The only reason to remove db_home is in case if there is an old
  60. # one lying around. This might be by a different user, so just
  61. # ignore errors. We should always make a unique name now.
  62. try:
  63. test_all.remove_test_path_directory()
  64. except:
  65. pass
  66. if __name__ == '__main__':
  67. test_main()