1997-01-16 18:04:10 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the bsddb C module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
1999-03-24 15:03:01 -04:00
|
|
|
import os
|
1997-01-16 18:04:10 -04:00
|
|
|
import bsddb
|
2001-12-07 12:43:19 -04:00
|
|
|
import dbhash # Just so we know it's imported
|
1997-01-16 18:04:10 -04:00
|
|
|
import tempfile
|
2001-03-21 20:40:23 -04:00
|
|
|
from test_support import verbose, verify
|
1997-01-16 18:04:10 -04:00
|
|
|
|
2002-04-22 23:11:05 -03:00
|
|
|
def test(openmethod, what, ondisk=1):
|
1997-01-16 18:04:10 -04:00
|
|
|
|
|
|
|
if verbose:
|
2002-04-22 23:11:05 -03:00
|
|
|
print '\nTesting: ', what, (ondisk and "on disk" or "in memory")
|
2000-10-23 14:22:08 -03:00
|
|
|
|
2002-04-22 23:11:05 -03:00
|
|
|
if ondisk:
|
|
|
|
fname = tempfile.mktemp()
|
|
|
|
else:
|
|
|
|
fname = None
|
1997-01-16 18:04:10 -04:00
|
|
|
f = openmethod(fname, 'c')
|
2001-03-21 20:40:23 -04:00
|
|
|
verify(f.keys() == [])
|
1997-01-16 18:04:10 -04:00
|
|
|
if verbose:
|
1998-03-26 15:42:58 -04:00
|
|
|
print 'creation...'
|
1997-01-16 18:04:10 -04:00
|
|
|
f['0'] = ''
|
|
|
|
f['a'] = 'Guido'
|
|
|
|
f['b'] = 'van'
|
|
|
|
f['c'] = 'Rossum'
|
|
|
|
f['d'] = 'invented'
|
|
|
|
f['f'] = 'Python'
|
|
|
|
if verbose:
|
1998-03-26 15:42:58 -04:00
|
|
|
print '%s %s %s' % (f['a'], f['b'], f['c'])
|
1997-01-16 18:04:10 -04:00
|
|
|
|
|
|
|
if what == 'BTree' :
|
1998-03-26 15:42:58 -04:00
|
|
|
if verbose:
|
|
|
|
print 'key ordering...'
|
|
|
|
f.set_location(f.first()[0])
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
rec = f.next()
|
|
|
|
except KeyError:
|
2000-12-12 19:11:42 -04:00
|
|
|
if rec != f.last():
|
|
|
|
print 'Error, last != last!'
|
1998-03-26 15:42:58 -04:00
|
|
|
f.previous()
|
|
|
|
break
|
|
|
|
if verbose:
|
|
|
|
print rec
|
|
|
|
if not f.has_key('a'):
|
|
|
|
print 'Error, missing key!'
|
1997-01-16 18:04:10 -04:00
|
|
|
|
|
|
|
f.sync()
|
|
|
|
f.close()
|
2002-04-22 23:11:05 -03:00
|
|
|
if ondisk:
|
|
|
|
# if we're using an in-memory only db, we can't reopen it
|
|
|
|
# so finish here.
|
|
|
|
if verbose:
|
|
|
|
print 'modification...'
|
|
|
|
f = openmethod(fname, 'w')
|
|
|
|
f['d'] = 'discovered'
|
1997-01-16 18:04:10 -04:00
|
|
|
|
1998-03-26 15:42:58 -04:00
|
|
|
if verbose:
|
2002-04-22 23:11:05 -03:00
|
|
|
print 'access...'
|
|
|
|
for key in f.keys():
|
|
|
|
word = f[key]
|
|
|
|
if verbose:
|
|
|
|
print word
|
1997-01-16 18:04:10 -04:00
|
|
|
|
2002-04-22 23:11:05 -03:00
|
|
|
f.close()
|
|
|
|
try:
|
|
|
|
os.remove(fname)
|
|
|
|
except os.error:
|
|
|
|
pass
|
1997-01-16 18:04:10 -04:00
|
|
|
|
|
|
|
types = [(bsddb.btopen, 'BTree'),
|
1998-03-26 15:42:58 -04:00
|
|
|
(bsddb.hashopen, 'Hash Table'),
|
2002-04-22 23:11:05 -03:00
|
|
|
(bsddb.btopen, 'BTree', 0),
|
|
|
|
(bsddb.hashopen, 'Hash Table', 0),
|
1998-03-26 15:42:58 -04:00
|
|
|
# (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
|
1997-01-16 18:04:10 -04:00
|
|
|
# appears broken... at least on
|
1998-03-26 15:42:58 -04:00
|
|
|
# Solaris Intel - rmasse 1/97
|
|
|
|
]
|
1997-01-16 18:04:10 -04:00
|
|
|
|
|
|
|
for type in types:
|
2002-04-22 23:11:05 -03:00
|
|
|
test(*type)
|