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