mirror of
https://github.com/python/cpython.git
synced 2025-10-29 20:51:26 +00:00
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61049 | christian.heimes | 2008-02-24 13:26:16 +0100 (Sun, 24 Feb 2008) | 1 line Use PY_FORMAT_SIZE_T instead of z for string formatting. Thanks Neal. ........ r61051 | mark.dickinson | 2008-02-24 19:12:36 +0100 (Sun, 24 Feb 2008) | 2 lines Remove duplicate 'import re' in decimal.py ........ r61052 | neal.norwitz | 2008-02-24 19:47:03 +0100 (Sun, 24 Feb 2008) | 11 lines Create a db_home directory with a unique name so multiple users can run the test simultaneously. The simplest thing I found that worked on both Windows and Unix was to use the PID. It's unique so should be sufficient. This should prevent many of the spurious failures of the automated tests since they run as different users. Also cleanup the directory consistenly in the tearDown methods. It would be nice if someone ensured that the directories are always created with a consistent name. ........ r61057 | christian.heimes | 2008-02-24 23:48:05 +0100 (Sun, 24 Feb 2008) | 2 lines Added dependency rules for Objects/stringlib/*.h stringobject, unicodeobject and the two formatters are rebuild whenever a header files changes ........
105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
"""TestCases for checking that it does not segfault when a DBEnv object
|
|
is closed before its DB objects.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
try:
|
|
# For Pythons w/distutils pybsddb
|
|
from bsddb3 import db
|
|
except ImportError:
|
|
# For Python 2.3
|
|
from bsddb import db
|
|
|
|
from bsddb.test.test_all import verbose
|
|
|
|
# We're going to get warnings in this module about trying to close the db when
|
|
# its env is already closed. Let's just ignore those.
|
|
try:
|
|
import warnings
|
|
except ImportError:
|
|
pass
|
|
else:
|
|
warnings.filterwarnings('ignore',
|
|
message='DB could not be closed in',
|
|
category=RuntimeWarning)
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
class DBEnvClosedEarlyCrash(unittest.TestCase):
|
|
def setUp(self):
|
|
self.homeDir = os.path.join(tempfile.gettempdir(), 'db_home%d'%os.getpid())
|
|
try: os.mkdir(self.homeDir)
|
|
except os.error: pass
|
|
tempfile.tempdir = self.homeDir
|
|
self.filename = os.path.split(tempfile.mktemp())[1]
|
|
tempfile.tempdir = None
|
|
|
|
def tearDown(self):
|
|
from test import test_support
|
|
test_support.rmtree(self.homeDir)
|
|
|
|
def test01_close_dbenv_before_db(self):
|
|
dbenv = db.DBEnv()
|
|
dbenv.open(self.homeDir,
|
|
db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
|
|
0o666)
|
|
|
|
d = db.DB(dbenv)
|
|
d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0o666)
|
|
|
|
try:
|
|
dbenv.close()
|
|
except db.DBError:
|
|
try:
|
|
d.close()
|
|
except db.DBError:
|
|
return
|
|
assert 0, \
|
|
"DB close did not raise an exception about its "\
|
|
"DBEnv being trashed"
|
|
|
|
# XXX This may fail when using older versions of BerkeleyDB.
|
|
# E.g. 3.2.9 never raised the exception.
|
|
assert 0, "dbenv did not raise an exception about its DB being open"
|
|
|
|
|
|
def test02_close_dbenv_delete_db_success(self):
|
|
dbenv = db.DBEnv()
|
|
dbenv.open(self.homeDir,
|
|
db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
|
|
0o666)
|
|
|
|
d = db.DB(dbenv)
|
|
d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0o666)
|
|
|
|
try:
|
|
dbenv.close()
|
|
except db.DBError:
|
|
pass # good, it should raise an exception
|
|
|
|
del d
|
|
try:
|
|
import gc
|
|
except ImportError:
|
|
gc = None
|
|
if gc:
|
|
# force d.__del__ [DB_dealloc] to be called
|
|
gc.collect()
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
def test_suite():
|
|
suite = unittest.TestSuite()
|
|
suite.addTest(unittest.makeSuite(DBEnvClosedEarlyCrash))
|
|
return suite
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(defaultTest='test_suite')
|