blob: e5780ea80433b5a9fcbd99d6c0ca4d87e1bdf7c1 [file] [log] [blame]
Guido van Rossum228b8e81997-04-02 06:13:34 +00001#! /usr/bin/env python
2"""Test script for the bsddb C module
3 Roger E. Masse
4"""
Guido van Rossum9a744a91999-04-08 20:27:54 +00005
6import os
Guido van Rossum228b8e81997-04-02 06:13:34 +00007import bsddb
8import tempfile
9from test_support import verbose
10
11def test(openmethod, what):
12
13 if verbose:
Guido van Rossum548703a1998-03-26 22:14:20 +000014 print '\nTesting: ', what
15
Guido van Rossum228b8e81997-04-02 06:13:34 +000016 fname = tempfile.mktemp()
17 f = openmethod(fname, 'c')
18 if verbose:
Guido van Rossum548703a1998-03-26 22:14:20 +000019 print 'creation...'
Guido van Rossum228b8e81997-04-02 06:13:34 +000020 f['0'] = ''
21 f['a'] = 'Guido'
22 f['b'] = 'van'
23 f['c'] = 'Rossum'
24 f['d'] = 'invented'
25 f['f'] = 'Python'
26 if verbose:
Guido van Rossum548703a1998-03-26 22:14:20 +000027 print '%s %s %s' % (f['a'], f['b'], f['c'])
Guido van Rossum228b8e81997-04-02 06:13:34 +000028
29 if what == 'BTree' :
Guido van Rossum548703a1998-03-26 22:14:20 +000030 if verbose:
31 print 'key ordering...'
32 f.set_location(f.first()[0])
33 while 1:
34 try:
35 rec = f.next()
36 except KeyError:
37 if rec <> f.last():
38 print 'Error, last <> last!'
39 f.previous()
40 break
41 if verbose:
42 print rec
43 if not f.has_key('a'):
44 print 'Error, missing key!'
Guido van Rossum228b8e81997-04-02 06:13:34 +000045
46 f.sync()
47 f.close()
48 if verbose:
Guido van Rossum548703a1998-03-26 22:14:20 +000049 print 'modification...'
Guido van Rossum228b8e81997-04-02 06:13:34 +000050 f = openmethod(fname, 'w')
51 f['d'] = 'discovered'
52
53 if verbose:
Guido van Rossum548703a1998-03-26 22:14:20 +000054 print 'access...'
Guido van Rossum228b8e81997-04-02 06:13:34 +000055 for key in f.keys():
Guido van Rossum548703a1998-03-26 22:14:20 +000056 word = f[key]
57 if verbose:
58 print word
Guido van Rossum228b8e81997-04-02 06:13:34 +000059
60 f.close()
Guido van Rossum9a744a91999-04-08 20:27:54 +000061 try:
62 os.remove(fname)
63 except os.error:
64 pass
Guido van Rossum228b8e81997-04-02 06:13:34 +000065
66types = [(bsddb.btopen, 'BTree'),
Guido van Rossum548703a1998-03-26 22:14:20 +000067 (bsddb.hashopen, 'Hash Table'),
68 # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
Guido van Rossum228b8e81997-04-02 06:13:34 +000069 # appears broken... at least on
Guido van Rossum548703a1998-03-26 22:14:20 +000070 # Solaris Intel - rmasse 1/97
71 ]
Guido van Rossum228b8e81997-04-02 06:13:34 +000072
73for type in types:
74 test(type[0], type[1])