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