1996-12-10 00:06:24 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the dbm module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
|
|
|
import dbm
|
|
|
|
from dbm import error
|
2001-01-17 21:51:36 +00:00
|
|
|
from test_support import verbose
|
1996-12-20 22:36:52 +00:00
|
|
|
|
2000-09-18 17:56:58 +00:00
|
|
|
filename = '/tmp/delete_me'
|
1996-12-10 00:06:24 +00:00
|
|
|
|
|
|
|
d = dbm.open(filename, 'c')
|
|
|
|
d['a'] = 'b'
|
|
|
|
d['12345678910'] = '019237410982340912840198242'
|
|
|
|
d.keys()
|
1996-12-20 22:36:52 +00:00
|
|
|
if d.has_key('a'):
|
|
|
|
if verbose:
|
1998-03-26 19:42:58 +00:00
|
|
|
print 'Test dbm keys: ', d.keys()
|
2000-09-18 17:56:58 +00:00
|
|
|
|
1996-12-10 00:06:24 +00: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 17:56:58 +00: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-10 00:06:24 +00:00
|
|
|
except:
|
|
|
|
pass
|