summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bsddb.py
blob: 192c6e2f2eca5676e0341edc9bc91902c1dae416 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin/env python
"""Test script for the bsddb C module
   Roger E. Masse
"""

import os
import bsddb
import tempfile
from test_support import verbose, verify

def test(openmethod, what):

    if verbose:
        print '\nTesting: ', what

    fname = tempfile.mktemp()
    f = openmethod(fname, 'c')
    verify(f.keys() == [])
    if verbose:
        print 'creation...'
    f['0'] = ''
    f['a'] = 'Guido'
    f['b'] = 'van'
    f['c'] = 'Rossum'
    f['d'] = 'invented'
    f['f'] = 'Python'
    if verbose:
        print '%s %s %s' % (f['a'], f['b'], f['c'])

    if what == 'BTree' :
        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!'

    f.sync()
    f.close()
    if verbose:
        print 'modification...'
    f = openmethod(fname, 'w')
    f['d'] = 'discovered'

    if verbose:
        print 'access...'
    for key in f.keys():
        word = f[key]
        if verbose:
            print word

    f.close()
    try:
        os.remove(fname)
    except os.error:
        pass

types = [(bsddb.btopen, 'BTree'),
         (bsddb.hashopen, 'Hash Table'),
         # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85
         #                                   appears broken... at least on
         #                                   Solaris Intel - rmasse 1/97
         ]

for type in types:
    test(type[0], type[1])