Debian Codegraph @

cpython27/Lib/test/test_bsddb3.py

raw symbols SCIP
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
12 # Skip test if _bsddb module was not built.
13 import_module('_bsddb')
14 # Silence Py3k warning
15 import_module('bsddb', deprecated=True)
16
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.
19 if __name__ != '__main__':
20 requires('bsddb')
21
22 verbose = False
23 if 'verbose' in sys.argv:
24 verbose = True
25 sys.argv.remove('verbose')
26
27 if 'silent' in sys.argv: # take care of old flag, just in case
28 verbose = False
29 sys.argv.remove('silent')
30
31 # bpo-30778: test_bsddb3 crashs randomly on Windows XP
32 if hasattr(sys, 'getwindowsversion') and sys.getwindowsversion()[:2] < (6, 0):
33 raise unittest.SkipTest("bpo-30778: skip tests on Windows XP")
34
35
36 class TimingCheck(unittest.TestCase):
37
38 """This class is not a real test. Its purpose is to print a message
39 periodically when the test runs slowly. This will prevent the buildbots
40 from timing out on slow machines."""
41
42 # How much time in seconds before printing a 'Still working' message.
43 # Since this is run at most once between each test module, use a smaller
44 # interval than other tests.
45 _PRINT_WORKING_MSG_INTERVAL = 4 * 60
46
47 # next_time is used as a global variable that survives each instance.
48 # This is necessary since a new instance will be created for each test.
49 next_time = time.time() + _PRINT_WORKING_MSG_INTERVAL
50
51 def testCheckElapsedTime(self):
52 # Print still working message since these tests can be really slow.
53 now = time.time()
54 if self.next_time <= now:
55 TimingCheck.next_time = now + self._PRINT_WORKING_MSG_INTERVAL
56 sys.__stdout__.write(' test_bsddb3 still working, be patient...\n')
57 sys.__stdout__.flush()
58
59
60 # For invocation through regrtest
61 def test_main():
62 from bsddb import db
63 from bsddb.test import test_all
64 test_all.set_test_path_prefix(os.path.join(tempfile.gettempdir(),
65 'z-test_bsddb3-%s' %
66 os.getpid()))
67 # Please leave this print in, having this show up in the buildbots
68 # makes diagnosing problems a lot easier.
69 print >>sys.stderr, db.DB_VERSION_STRING
70 print >>sys.stderr, 'Test path prefix: ', test_all.get_test_path_prefix()
71 try:
72 run_unittest(test_all.suite(module_prefix='bsddb.test.',
73 timing_check=TimingCheck))
74 finally:
75 # The only reason to remove db_home is in case if there is an old
76 # one lying around. This might be by a different user, so just
77 # ignore errors. We should always make a unique name now.
78 try:
79 test_all.remove_test_path_directory()
80 except:
81 pass
82
83
84 if __name__ == '__main__':
85 test_main()