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