1996-12-17 15:54:27 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the gdbm module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
2000-10-23 14:22:08 -03:00
|
|
|
|
1996-12-17 15:54:27 -04:00
|
|
|
import gdbm
|
|
|
|
from gdbm import error
|
2000-02-07 13:15:48 -04:00
|
|
|
from test_support import verbose, TestFailed
|
1996-12-20 18:36:52 -04:00
|
|
|
|
1996-12-17 15:54:27 -04:00
|
|
|
filename= '/tmp/delete_me'
|
|
|
|
|
|
|
|
g = gdbm.open(filename, 'c')
|
|
|
|
g['a'] = 'b'
|
|
|
|
g['12345678910'] = '019237410982340912840198242'
|
|
|
|
a = g.keys()
|
|
|
|
if verbose:
|
|
|
|
print 'Test gdbm file keys: ', a
|
2000-10-23 14:22:08 -03:00
|
|
|
|
1996-12-17 15:54:27 -04:00
|
|
|
g.has_key('a')
|
|
|
|
g.close()
|
2000-02-07 13:15:48 -04:00
|
|
|
try:
|
|
|
|
g['a']
|
|
|
|
except error:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise TestFailed, "expected gdbm.error accessing closed database"
|
1996-12-17 15:54:27 -04:00
|
|
|
g = gdbm.open(filename, 'r')
|
|
|
|
g.close()
|
|
|
|
g = gdbm.open(filename, 'w')
|
|
|
|
g.close()
|
|
|
|
g = gdbm.open(filename, 'n')
|
|
|
|
g.close()
|
2000-12-18 13:28:05 -04:00
|
|
|
try:
|
|
|
|
g = gdbm.open(filename, 'rx')
|
|
|
|
g.close()
|
|
|
|
except error:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise TestFailed, "expected gdbm.error when passing invalid open flags"
|
1996-12-17 15:54:27 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
|
|
|
os.unlink(filename)
|
|
|
|
except:
|
|
|
|
pass
|