cleanup test_dbtables to use mkdtemp. cleanup dbtables to pass txn as a

keyword argument whenever possible to avoid bugs and confusion.  (dbtables.py
line 447 self.db.get using txn as a non-keyword was an actual bug due to this)
This commit is contained in:
Gregory P. Smith 2007-10-18 07:56:54 +00:00
parent d97110dd1b
commit afed3a4552
2 changed files with 18 additions and 19 deletions

View File

@ -20,8 +20,9 @@ _cvsid = '$Id$'
import re
import sys
import copy
import xdrlib
import random
import struct
import base64
from types import ListType, StringType
import cPickle as pickle
@ -255,7 +256,7 @@ class bsdTableDB :
flags=DB_RMW))
tablelist.append(table)
# delete 1st, in case we opened with DB_DUP
self.db.delete(_table_names_key, txn)
self.db.delete(_table_names_key, txn=txn)
self.db.put(_table_names_key, pickle.dumps(tablelist, 1), txn=txn)
txn.commit()
@ -329,7 +330,7 @@ class bsdTableDB :
# store the table's new extended column list
if newcolumnlist != oldcolumnlist :
# delete the old one first since we opened with DB_DUP
self.db.delete(columnlist_key, txn)
self.db.delete(columnlist_key, txn=txn)
self.db.put(columnlist_key,
pickle.dumps(newcolumnlist, 1),
txn=txn)
@ -362,10 +363,9 @@ class bsdTableDB :
# Generate a random 64-bit row ID string
# (note: this code has <64 bits of randomness
# but it's plenty for our database id needs!)
p = xdrlib.Packer()
p.pack_int(int(random.random()*2147483647))
p.pack_int(int(random.random()*2147483647))
newid = p.get_buffer()
newid = struct.pack('ll',
random.randint(0, 2147483647),
random.randint(0, 2147483647))
# Guarantee uniqueness by adding this key to the database
try:
@ -444,10 +444,10 @@ class bsdTableDB :
try:
dataitem = self.db.get(
_data_key(table, column, rowid),
txn)
txn=txn)
self.db.delete(
_data_key(table, column, rowid),
txn)
txn=txn)
except DBNotFoundError:
# XXXXXXX row key somehow didn't exist, assume no
# error
@ -490,13 +490,13 @@ class bsdTableDB :
# delete the data key
try:
self.db.delete(_data_key(table, column, rowid),
txn)
txn=txn)
except DBNotFoundError:
# XXXXXXX column may not exist, assume no error
pass
try:
self.db.delete(_rowid_key(table, rowid), txn)
self.db.delete(_rowid_key(table, rowid), txn=txn)
except DBNotFoundError:
# XXXXXXX row key somehow didn't exist, assume no error
pass
@ -652,7 +652,7 @@ class bsdTableDB :
txn = self.env.txn_begin()
# delete the column list
self.db.delete(_columns_key(table), txn)
self.db.delete(_columns_key(table), txn=txn)
cur = self.db.cursor(txn)
@ -691,7 +691,7 @@ class bsdTableDB :
# hmm, it wasn't there, oh well, that's what we want.
pass
# delete 1st, incase we opened with DB_DUP
self.db.delete(_table_names_key, txn)
self.db.delete(_table_names_key, txn=txn)
self.db.put(_table_names_key, pickle.dumps(tablelist, 1), txn=txn)
txn.commit()

View File

@ -21,6 +21,8 @@
# $Id$
import sys, os, re
import tempfile
import shutil
try:
import cPickle
pickle = cPickle
@ -47,8 +49,8 @@ class TableDBTestCase(unittest.TestCase):
db_name = 'test-table.db'
def setUp(self):
homeDir = os.path.join(tempfile.gettempdir(), 'db_home')
self.homeDir = homeDir
homeDir = tempfile.mkdtemp()
self.testHomeDir = homeDir
try: os.mkdir(homeDir)
except os.error: pass
self.tdb = dbtables.bsdTableDB(
@ -56,10 +58,7 @@ class TableDBTestCase(unittest.TestCase):
def tearDown(self):
self.tdb.close()
import glob
files = glob.glob(os.path.join(self.homeDir, '*'))
for file in files:
os.remove(file)
shutil.rmtree(self.testHomeDir)
def test01(self):
tabname = "test01"