Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | """Test script for the bsddb C module |
| 3 | Roger E. Masse |
| 4 | """ |
| 5 | import bsddb |
| 6 | import tempfile |
| 7 | from test_support import verbose |
| 8 | |
| 9 | def test(openmethod, what): |
| 10 | |
| 11 | if verbose: |
| 12 | print '\nTesting: ', what |
| 13 | |
| 14 | fname = tempfile.mktemp() |
| 15 | f = openmethod(fname, 'c') |
| 16 | if verbose: |
| 17 | print 'creation...' |
| 18 | f['0'] = '' |
| 19 | f['a'] = 'Guido' |
| 20 | f['b'] = 'van' |
| 21 | f['c'] = 'Rossum' |
| 22 | f['d'] = 'invented' |
| 23 | f['f'] = 'Python' |
| 24 | if verbose: |
| 25 | print '%s %s %s' % (f['a'], f['b'], f['c']) |
| 26 | |
| 27 | if what == 'BTree' : |
| 28 | if verbose: |
| 29 | print 'key ordering...' |
| 30 | f.set_location(f.first()[0]) |
| 31 | while 1: |
| 32 | try: |
| 33 | rec = f.next() |
| 34 | except KeyError: |
| 35 | if rec <> f.last(): |
| 36 | print 'Error, last <> last!' |
| 37 | f.previous() |
| 38 | break |
| 39 | if verbose: |
| 40 | print rec |
| 41 | if not f.has_key('a'): |
| 42 | print 'Error, missing key!' |
| 43 | |
| 44 | f.sync() |
| 45 | f.close() |
| 46 | if verbose: |
| 47 | print 'modification...' |
| 48 | f = openmethod(fname, 'w') |
| 49 | f['d'] = 'discovered' |
| 50 | |
| 51 | if verbose: |
| 52 | print 'access...' |
| 53 | for key in f.keys(): |
| 54 | word = f[key] |
| 55 | if verbose: |
| 56 | print word |
| 57 | |
| 58 | f.close() |
| 59 | |
| 60 | types = [(bsddb.btopen, 'BTree'), |
| 61 | (bsddb.hashopen, 'Hash Table'), |
| 62 | # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 |
| 63 | # appears broken... at least on |
| 64 | # Solaris Intel - rmasse 1/97 |
| 65 | ] |
| 66 | |
| 67 | for type in types: |
| 68 | test(type[0], type[1]) |
| 69 | |