1996-12-18 03:54:27 +08:00
|
|
|
#! /usr/bin/env python
|
|
|
|
"""Test script for the gdbm module
|
|
|
|
Roger E. Masse
|
|
|
|
"""
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1996-12-18 03:54:27 +08:00
|
|
|
import gdbm
|
|
|
|
from gdbm import error
|
2002-07-24 03:04:11 +08:00
|
|
|
from test.test_support import verbose, verify, TestFailed
|
1996-12-21 06:36:52 +08:00
|
|
|
|
1996-12-18 03:54:27 +08:00
|
|
|
filename= '/tmp/delete_me'
|
|
|
|
|
|
|
|
g = gdbm.open(filename, 'c')
|
2001-03-22 08:40:23 +08:00
|
|
|
verify(g.keys() == [])
|
1996-12-18 03:54:27 +08:00
|
|
|
g['a'] = 'b'
|
|
|
|
g['12345678910'] = '019237410982340912840198242'
|
|
|
|
a = g.keys()
|
|
|
|
if verbose:
|
|
|
|
print 'Test gdbm file keys: ', a
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1996-12-18 03:54:27 +08:00
|
|
|
g.has_key('a')
|
|
|
|
g.close()
|
2000-02-08 01:15:48 +08:00
|
|
|
try:
|
|
|
|
g['a']
|
|
|
|
except error:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise TestFailed, "expected gdbm.error accessing closed database"
|
1996-12-18 03:54:27 +08:00
|
|
|
g = gdbm.open(filename, 'r')
|
|
|
|
g.close()
|
|
|
|
g = gdbm.open(filename, 'w')
|
|
|
|
g.close()
|
|
|
|
g = gdbm.open(filename, 'n')
|
|
|
|
g.close()
|
2000-12-19 01:28:05 +08: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-18 03:54:27 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
|
|
|
os.unlink(filename)
|
|
|
|
except:
|
|
|
|
pass
|