2007-09-06 19:59:59 -03:00
|
|
|
# http://bugs.python.org/issue1413192
|
2006-01-25 01:21:55 -04:00
|
|
|
#
|
2007-09-06 19:59:59 -03:00
|
|
|
# See the bug report for details.
|
2006-01-25 01:21:55 -04:00
|
|
|
# The problem was that the env was deallocated prior to the txn.
|
|
|
|
|
2007-08-22 18:32:34 -03:00
|
|
|
import shutil
|
|
|
|
import tempfile
|
2008-03-19 20:01:17 -03:00
|
|
|
from test.test_support import catch_warning
|
2007-10-19 04:31:20 -03:00
|
|
|
import warnings
|
2008-03-19 20:01:17 -03:00
|
|
|
|
2006-01-29 19:54:38 -04:00
|
|
|
try:
|
|
|
|
# For Pythons w/distutils and add-on pybsddb
|
|
|
|
from bsddb3 import db
|
|
|
|
except ImportError:
|
|
|
|
# For Python >= 2.3 builtin bsddb distribution
|
|
|
|
from bsddb import db
|
2006-01-25 01:21:55 -04:00
|
|
|
|
2007-08-22 18:32:34 -03:00
|
|
|
env_name = tempfile.mkdtemp()
|
2006-01-25 01:21:55 -04:00
|
|
|
|
2007-09-06 19:59:59 -03:00
|
|
|
# Wrap test operation in a class so we can control destruction rather than
|
|
|
|
# waiting for the controlling Python executable to exit
|
|
|
|
|
|
|
|
class Context:
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.env = db.DBEnv()
|
|
|
|
self.env.open(env_name,
|
|
|
|
db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_MPOOL)
|
|
|
|
self.the_txn = self.env.txn_begin()
|
|
|
|
|
|
|
|
self.map = db.DB(self.env)
|
|
|
|
self.map.open('xxx.db', "p",
|
|
|
|
db.DB_HASH, db.DB_CREATE, 0666, txn=self.the_txn)
|
|
|
|
del self.env
|
|
|
|
del self.the_txn
|
|
|
|
|
2006-01-25 01:21:55 -04:00
|
|
|
|
2008-03-19 20:01:17 -03:00
|
|
|
with catch_warning():
|
|
|
|
warnings.filterwarnings('ignore', 'DBTxn aborted in destructor')
|
2007-10-19 04:31:20 -03:00
|
|
|
context = Context()
|
|
|
|
del context
|
2008-03-19 20:01:17 -03:00
|
|
|
|
2007-08-22 18:32:34 -03:00
|
|
|
|
2007-09-06 19:59:59 -03:00
|
|
|
# try not to leave a turd
|
2007-08-22 18:32:34 -03:00
|
|
|
try:
|
|
|
|
shutil.rmtree(env_name)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|