home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 June / maximum-cd-2011-06.iso / DiscContents / LibO_3.3.1_Win_x86_install_multi.exe / libreoffice1.cab / test_bsddb3.py < prev    next >
Encoding:
Python Source  |  2011-02-15  |  2.6 KB  |  77 lines

  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.  
  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.
  14. if __name__ != '__main__':
  15.     requires('bsddb')
  16.  
  17. verbose = False
  18. if 'verbose' in sys.argv:
  19.     verbose = True
  20.     sys.argv.remove('verbose')
  21.  
  22. if 'silent' in sys.argv:  # take care of old flag, just in case
  23.     verbose = False
  24.     sys.argv.remove('silent')
  25.  
  26.  
  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.  
  51. # For invocation through regrtest
  52. def test_main():
  53.     from bsddb import db
  54.     from bsddb.test import test_all
  55.     test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
  56.                                  'z-test_bsddb3-%s' %
  57.                                  os.getpid()))
  58.     # Please leave this print in, having this show up in the buildbots
  59.     # makes diagnosing problems a lot easier.
  60.     print >>sys.stderr, db.DB_VERSION_STRING
  61.     print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
  62.     try:
  63.         run_unittest(test_all.suite(module_prefix='bsddb.test.',
  64.                                     timing_check=TimingCheck))
  65.     finally:
  66.         # The only reason to remove db_home is in case if there is an old
  67.         # one lying around.  This might be by a different user, so just
  68.         # ignore errors.  We should always make a unique name now.
  69.         try:
  70.             test_all.remove_test_path_directory()
  71.         except:
  72.             pass
  73.  
  74.  
  75. if __name__ == '__main__':
  76.     test_main()
  77.