1997-04-02 02:13:34 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the bsddb C module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
1999-04-08 17:27:54 -03:00
|
|
|
|
|
|
|
import os
|
1997-04-02 02:13:34 -04:00
|
|
|
import bsddb
|
|
|
|
import tempfile
|
|
|
|
from test_support import verbose
|
|
|
|
|
|
|
|
def test(openmethod, what):
|
|
|
|
|
|
|
|
if verbose:
|
1998-03-26 18:14:20 -04:00
|
|
|
print '\nTesting: ', what
|
|
|
|
|
1997-04-02 02:13:34 -04:00
|
|
|
fname = tempfile.mktemp()
|
|
|
|
f = openmethod(fname, 'c')
|
|
|
|
if verbose:
|
1998-03-26 18:14:20 -04:00
|
|
|
print 'creation...'
|
1997-04-02 02:13:34 -04:00
|
|
|
f['0'] = ''
|
|
|
|
f['a'] = 'Guido'
|
|
|
|
f['b'] = 'van'
|
|
|
|
f['c'] = 'Rossum'
|
|
|
|
f['d'] = 'invented'
|
|
|
|
f['f'] = 'Python'
|
|
|
|
if verbose:
|
1998-03-26 18:14:20 -04:00
|
|
|
print '%s %s %s' % (f['a'], f['b'], f['c'])
|
1997-04-02 02:13:34 -04:00
|
|
|
|
|
|
|
if what == 'BTree' :
|
1998-03-26 18:14:20 -04: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-04-02 02:13:34 -04:00
|
|
|
|
|
|
|
f.sync()
|
|
|
|
f.close()
|
|
|
|
if verbose:
|
1998-03-26 18:14:20 -04:00
|
|
|
print 'modification...'
|
1997-04-02 02:13:34 -04:00
|
|
|
f = openmethod(fname, 'w')
|
|
|
|
f['d'] = 'discovered'
|
|
|
|
|
|
|
|
if verbose:
|
1998-03-26 18:14:20 -04:00
|
|
|
print 'access...'
|
1997-04-02 02:13:34 -04:00
|
|
|
for key in f.keys():
|
1998-03-26 18:14:20 -04:00
|
|
|
word = f[key]
|
|
|
|
if verbose:
|
|
|
|
print word
|
1997-04-02 02:13:34 -04:00
|
|
|
|
|
|
|
f.close()
|
1999-04-08 17:27:54 -03:00
|
|
|
try:
|
|
|
|
os.remove(fname)
|
|
|
|
except os.error:
|
|
|
|
pass
|
1997-04-02 02:13:34 -04:00
|
|
|
|
|
|
|
types = [(bsddb.btopen, 'BTree'),
|
1998-03-26 18:14:20 -04:00
|
|
|
(bsddb.hashopen, 'Hash Table'),
|
|
|
|
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
|
1997-04-02 02:13:34 -04:00
|
|
|
# appears broken... at least on
|
1998-03-26 18:14:20 -04:00
|
|
|
# Solaris Intel - rmasse 1/97
|
|
|
|
]
|
1997-04-02 02:13:34 -04:00
|
|
|
|
|
|
|
for type in types:
|
|
|
|
test(type[0], type[1])
|