1996-12-09 20:06:24 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the dbm module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
|
|
|
import dbm
|
|
|
|
from dbm import error
|
2002-07-23 16:04:11 -03:00
|
|
|
from test.test_support import verbose, verify
|
1996-12-20 18:36:52 -04:00
|
|
|
|
2000-09-18 14:56:58 -03:00
|
|
|
filename = '/tmp/delete_me'
|
1996-12-09 20:06:24 -04:00
|
|
|
|
|
|
|
d = dbm.open(filename, 'c')
|
2001-03-21 20:40:23 -04:00
|
|
|
verify(d.keys() == [])
|
1996-12-09 20:06:24 -04:00
|
|
|
d['a'] = 'b'
|
|
|
|
d['12345678910'] = '019237410982340912840198242'
|
|
|
|
d.keys()
|
1996-12-20 18:36:52 -04:00
|
|
|
if d.has_key('a'):
|
|
|
|
if verbose:
|
1998-03-26 15:42:58 -04:00
|
|
|
print 'Test dbm keys: ', d.keys()
|
2000-09-18 14:56:58 -03:00
|
|
|
|
1996-12-09 20:06:24 -04:00
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'r')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'rw')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'w')
|
|
|
|
d.close()
|
|
|
|
d = dbm.open(filename, 'n')
|
|
|
|
d.close()
|
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
2000-09-18 14:56:58 -03:00
|
|
|
if dbm.library == "ndbm":
|
|
|
|
# classic dbm
|
|
|
|
os.unlink(filename + '.dir')
|
|
|
|
os.unlink(filename + '.pag')
|
|
|
|
elif dbm.library == "BSD db":
|
|
|
|
# BSD DB's compatibility layer
|
|
|
|
os.unlink(filename + '.db')
|
|
|
|
else:
|
|
|
|
# GNU gdbm compatibility layer
|
|
|
|
os.unlink(filename)
|
1996-12-09 20:06:24 -04:00
|
|
|
except:
|
|
|
|
pass
|