summaryrefslogtreecommitdiffstats
path: root/Lib/bsddb
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2003-10-01 06:48:51 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2003-10-01 06:48:51 (GMT)
commitbe0db8b125951adb475fc388de9aebabcabbf6e3 (patch)
treedbfbc01617f45a987f58a809d9784ed8974c8cd7 /Lib/bsddb
parentefb3a161c3636c121261c4334ce151ef5d51418e (diff)
downloadcpython-be0db8b125951adb475fc388de9aebabcabbf6e3.zip
cpython-be0db8b125951adb475fc388de9aebabcabbf6e3.tar.gz
cpython-be0db8b125951adb475fc388de9aebabcabbf6e3.tar.bz2
bsddb3 4.2.2, adds DBCursor.get_current_size() method to return the length
of the current value without reading the value itself.
Diffstat (limited to 'Lib/bsddb')
-rw-r--r--Lib/bsddb/test/test_basics.py72
1 files changed, 36 insertions, 36 deletions
diff --git a/Lib/bsddb/test/test_basics.py b/Lib/bsddb/test/test_basics.py
index 2e6b922..93a7fb7 100644
--- a/Lib/bsddb/test/test_basics.py
+++ b/Lib/bsddb/test/test_basics.py
@@ -49,6 +49,8 @@ class BasicTestCase(unittest.TestCase):
envflags = 0
envsetflags = 0
+ _numKeys = 1002 # PRIVATE. NOTE: must be an even value
+
def setUp(self):
if self.useEnv:
homeDir = os.path.join(os.path.dirname(sys.argv[0]), 'db_home')
@@ -106,17 +108,23 @@ class BasicTestCase(unittest.TestCase):
- def populateDB(self):
+ def populateDB(self, _txn=None):
d = self.d
- for x in range(500):
- key = '%04d' % (1000 - x) # insert keys in reverse order
+
+ for x in range(self._numKeys/2):
+ key = '%04d' % (self._numKeys - x) # insert keys in reverse order
data = self.makeData(key)
- d.put(key, data)
+ d.put(key, data, _txn)
- for x in range(500):
+ d.put('empty value', '', _txn)
+
+ for x in range(self._numKeys/2-1):
key = '%04d' % x # and now some in forward order
data = self.makeData(key)
- d.put(key, data)
+ d.put(key, data, _txn)
+
+ if _txn:
+ _txn.commit()
num = len(d)
if verbose:
@@ -236,20 +244,20 @@ class BasicTestCase(unittest.TestCase):
if verbose:
print data
- assert len(d) == 1000
+ assert len(d) == self._numKeys
keys = d.keys()
- assert len(keys) == 1000
+ assert len(keys) == self._numKeys
assert type(keys) == type([])
d['new record'] = 'a new record'
- assert len(d) == 1001
+ assert len(d) == self._numKeys+1
keys = d.keys()
- assert len(keys) == 1001
+ assert len(keys) == self._numKeys+1
d['new record'] = 'a replacement record'
- assert len(d) == 1001
+ assert len(d) == self._numKeys+1
keys = d.keys()
- assert len(keys) == 1001
+ assert len(keys) == self._numKeys+1
if verbose:
print "the first 10 keys are:"
@@ -261,7 +269,7 @@ class BasicTestCase(unittest.TestCase):
assert d.has_key('spam') == 0
items = d.items()
- assert len(items) == 1001
+ assert len(items) == self._numKeys+1
assert type(items) == type([])
assert type(items[0]) == type(())
assert len(items[0]) == 2
@@ -271,7 +279,7 @@ class BasicTestCase(unittest.TestCase):
pprint(items[:10])
values = d.values()
- assert len(values) == 1001
+ assert len(values) == self._numKeys+1
assert type(values) == type([])
if verbose:
@@ -293,7 +301,7 @@ class BasicTestCase(unittest.TestCase):
else:
txn = None
c = self.d.cursor(txn=txn)
-
+
rec = c.first()
count = 0
while rec is not None:
@@ -309,8 +317,9 @@ class BasicTestCase(unittest.TestCase):
rec = None
else:
self.fail("unexpected DBNotFoundError")
-
- assert count == 1000
+ assert c.get_current_size() == len(c.current()[1]), "%s != len(%r)" % (c.get_current_size(), c.current()[1])
+
+ assert count == self._numKeys
rec = c.last()
@@ -329,14 +338,20 @@ class BasicTestCase(unittest.TestCase):
else:
self.fail("unexpected DBNotFoundError")
- assert count == 1000
+ assert count == self._numKeys
rec = c.set('0505')
rec2 = c.current()
assert rec == rec2
assert rec[0] == '0505'
assert rec[1] == self.makeData('0505')
+ assert c.get_current_size() == len(rec[1])
+ # make sure we get empty values properly
+ rec = c.set('empty value')
+ assert rec[1] == ''
+ assert c.get_current_size() == 0
+
try:
n = c.set('bad key')
except db.DBNotFoundError, val:
@@ -575,23 +590,8 @@ class BasicTransactionTestCase(BasicTestCase):
def populateDB(self):
- d = self.d
txn = self.env.txn_begin()
- for x in range(500):
- key = '%04d' % (1000 - x) # insert keys in reverse order
- data = self.makeData(key)
- d.put(key, data, txn)
-
- for x in range(500):
- key = '%04d' % x # and now some in forward order
- data = self.makeData(key)
- d.put(key, data, txn)
-
- txn.commit()
-
- num = len(d)
- if verbose:
- print "created %d records" % num
+ BasicTestCase.populateDB(self, _txn=txn)
self.txn = self.env.txn_begin()
@@ -626,7 +626,7 @@ class BasicTransactionTestCase(BasicTestCase):
if verbose and count % 100 == 0:
print rec
rec = c.next()
- assert count == 1001
+ assert count == self._numKeys+1
c.close() # Cursors *MUST* be closed before commit!
self.txn.commit()
@@ -855,7 +855,7 @@ class BasicMultiDBTestCase(BasicTestCase):
if verbose and (count % 50) == 0:
print rec
rec = c1.next()
- assert count == 1000
+ assert count == self._numKeys
count = 0
rec = c2.first()