Test: Use temporary directory to test bsddb

This commit is contained in:
André Apitzsch 2022-03-09 19:31:00 +01:00 committed by Nick Hall
parent 21e94dec99
commit c5564bcd19

View File

@ -20,48 +20,41 @@
# test/LosHawlos_bsddbtest.py
from bsddb3 import dbshelve, db
import os
import sys
sys.path.append('../gramps')
import gramps.gen.const as const
import tempfile
from bsddb3 import db
print("Test that db.DBEnv().open() works")
env_name = os.path.expanduser(os.path.join(const.HOME_DIR, "test"))
if not os.path.isdir(env_name):
os.mkdir(env_name)
env = db.DBEnv()
env.set_cachesize(0,0x2000000)
env.set_lk_max_locks(25000)
env.set_lk_max_objects(25000)
# env.set_flags(db.DB_LOG_AUTOREMOVE,1)
"""
BSDDB change log settings using new method with renamed attributes
"""
autoremove_flag = None
autoremove_method = None
for flag in ["DB_LOG_AUTO_REMOVE", "DB_LOG_AUTOREMOVE"]:
if hasattr(db, flag):
autoremove_flag = getattr(db, flag)
break
for method in ["log_set_config", "set_flags"]:
if hasattr(env, method):
autoremove_method = getattr(env, method)
break
if autoremove_method and autoremove_flag:
autoremove_method(autoremove_flag, 1)
else:
print("Failed to set autoremove flag")
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
db.DB_INIT_LOG|db.DB_INIT_TXN|db.DB_THREAD
try:
env.open(env_name,env_flags)
except db.DBRunRecoveryError as e:
print("Exception: ")
print(e)
env.remove(env_name)
env.open(env_name,env_flags)
print("OK")
with tempfile.TemporaryDirectory() as env_name:
env = db.DBEnv()
env.set_cachesize(0,0x2000000)
env.set_lk_max_locks(25000)
env.set_lk_max_objects(25000)
# env.set_flags(db.DB_LOG_AUTOREMOVE,1)
"""
BSDDB change log settings using new method with renamed attributes
"""
autoremove_flag = None
autoremove_method = None
for flag in ["DB_LOG_AUTO_REMOVE", "DB_LOG_AUTOREMOVE"]:
if hasattr(db, flag):
autoremove_flag = getattr(db, flag)
break
for method in ["log_set_config", "set_flags"]:
if hasattr(env, method):
autoremove_method = getattr(env, method)
break
if autoremove_method and autoremove_flag:
autoremove_method(autoremove_flag, 1)
else:
print("Failed to set autoremove flag")
env_flags = db.DB_CREATE|db.DB_RECOVER|db.DB_PRIVATE|\
db.DB_INIT_MPOOL|db.DB_INIT_LOCK|\
db.DB_INIT_LOG|db.DB_INIT_TXN|db.DB_THREAD
try:
env.open(env_name,env_flags)
except db.DBRunRecoveryError as e:
print("Exception: ")
print(e)
env.remove(env_name)
env.open(env_name,env_flags)
print("OK")