1997-01-16 22:04:10 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the bsddb C module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
1999-03-24 19:03:01 +00:00
|
|
|
|
|
|
|
import os
|
1997-01-16 22:04:10 +00:00
|
|
|
import bsddb
|
|
|
|
import tempfile
|
|
|
|
from test_support import verbose
|
|
|
|
|
|
|
|
def test(openmethod, what):
|
|
|
|
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print '\nTesting: ', what
|
2000-10-23 17:22:08 +00:00
|
|
|
|
1997-01-16 22:04:10 +00:00
|
|
|
fname = tempfile.mktemp()
|
|
|
|
f = openmethod(fname, 'c')
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print 'creation...'
|
1997-01-16 22:04:10 +00:00
|
|
|
f['0'] = ''
|
|
|
|
f['a'] = 'Guido'
|
|
|
|
f['b'] = 'van'
|
|
|
|
f['c'] = 'Rossum'
|
|
|
|
f['d'] = 'invented'
|
|
|
|
f['f'] = 'Python'
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print '%s %s %s' % (f['a'], f['b'], f['c'])
|
1997-01-16 22:04:10 +00:00
|
|
|
|
|
|
|
if what == 'BTree' :
|
1998-03-26 19:42:58 +00:00
|
|
|
if verbose:
|
|
|
|
print 'key ordering...'
|
|
|
|
f.set_location(f.first()[0])
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
rec = f.next()
|
|
|
|
except KeyError:
|
2000-12-12 23:11:42 +00:00
|
|
|
if rec != f.last():
|
|
|
|
print 'Error, last != last!'
|
1998-03-26 19:42:58 +00:00
|
|
|
f.previous()
|
|
|
|
break
|
|
|
|
if verbose:
|
|
|
|
print rec
|
|
|
|
if not f.has_key('a'):
|
|
|
|
print 'Error, missing key!'
|
1997-01-16 22:04:10 +00:00
|
|
|
|
|
|
|
f.sync()
|
|
|
|
f.close()
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print 'modification...'
|
1997-01-16 22:04:10 +00:00
|
|
|
f = openmethod(fname, 'w')
|
|
|
|
f['d'] = 'discovered'
|
|
|
|
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print 'access...'
|
1997-01-16 22:04:10 +00:00
|
|
|
for key in f.keys():
|
1998-03-26 19:42:58 +00:00
|
|
|
word = f[key]
|
|
|
|
if verbose:
|
|
|
|
print word
|
1997-01-16 22:04:10 +00:00
|
|
|
|
|
|
|
f.close()
|
1999-03-24 19:03:01 +00:00
|
|
|
try:
|
|
|
|
os.remove(fname)
|
|
|
|
except os.error:
|
|
|
|
pass
|
1997-01-16 22:04:10 +00:00
|
|
|
|
|
|
|
types = [(bsddb.btopen, 'BTree'),
|
1998-03-26 19:42:58 +00:00
|
|
|
(bsddb.hashopen, 'Hash Table'),
|
|
|
|
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
|
1997-01-16 22:04:10 +00:00
|
|
|
# appears broken... at least on
|
1998-03-26 19:42:58 +00:00
|
|
|
# Solaris Intel - rmasse 1/97
|
|
|
|
]
|
1997-01-16 22:04:10 +00:00
|
|
|
|
|
|
|
for type in types:
|
|
|
|
test(type[0], type[1])
|