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 | """ |
Guido van Rossum | 9a744a9 | 1999-04-08 20:27:54 +0000 | [diff] [blame] | 5 | |
| 6 | import os |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 7 | import bsddb |
| 8 | import tempfile |
| 9 | from test_support import verbose |
| 10 | |
| 11 | def test(openmethod, what): |
| 12 | |
| 13 | if verbose: |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 14 | print '\nTesting: ', what |
| 15 | |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 16 | fname = tempfile.mktemp() |
| 17 | f = openmethod(fname, 'c') |
| 18 | if verbose: |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 19 | print 'creation...' |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 20 | 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 Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 27 | print '%s %s %s' % (f['a'], f['b'], f['c']) |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 28 | |
| 29 | if what == 'BTree' : |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 30 | 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 Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 45 | |
| 46 | f.sync() |
| 47 | f.close() |
| 48 | if verbose: |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 49 | print 'modification...' |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 50 | f = openmethod(fname, 'w') |
| 51 | f['d'] = 'discovered' |
| 52 | |
| 53 | if verbose: |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 54 | print 'access...' |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 55 | for key in f.keys(): |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 56 | word = f[key] |
| 57 | if verbose: |
| 58 | print word |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 59 | |
| 60 | f.close() |
Guido van Rossum | 9a744a9 | 1999-04-08 20:27:54 +0000 | [diff] [blame] | 61 | try: |
| 62 | os.remove(fname) |
| 63 | except os.error: |
| 64 | pass |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 65 | |
| 66 | types = [(bsddb.btopen, 'BTree'), |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 67 | (bsddb.hashopen, 'Hash Table'), |
| 68 | # (bsddb.rnopen,'Record Numbers'), 'put' for RECNO for bsddb 1.85 |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 69 | # appears broken... at least on |
Guido van Rossum | 548703a | 1998-03-26 22:14:20 +0000 | [diff] [blame] | 70 | # Solaris Intel - rmasse 1/97 |
| 71 | ] |
Guido van Rossum | 228b8e8 | 1997-04-02 06:13:34 +0000 | [diff] [blame] | 72 | |
| 73 | for type in types: |
| 74 | test(type[0], type[1]) |