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
|
2006-08-25 20:40:32 -03:00
|
|
|
from test.test_support import verbose, verify, TestFailed, TESTFN
|
1996-12-20 18:36:52 -04:00
|
|
|
|
2006-08-25 20:40:32 -03:00
|
|
|
filename = TESTFN
|
1996-12-17 15:54:27 -04:00
|
|
|
|
|
|
|
g = gdbm.open(filename, 'c')
|
2001-03-21 20:40:23 -04:00
|
|
|
verify(g.keys() == [])
|
2007-08-14 06:24:24 -03:00
|
|
|
g[b'a'] = b'b'
|
|
|
|
g[b'12345678910'] = b'019237410982340912840198242'
|
1996-12-17 15:54:27 -04:00
|
|
|
a = g.keys()
|
|
|
|
if verbose:
|
2007-02-09 01:37:30 -04:00
|
|
|
print('Test gdbm file keys: ', a)
|
2000-10-23 14:22:08 -03:00
|
|
|
|
2007-08-14 06:24:24 -03:00
|
|
|
b'a' in g
|
1996-12-17 15:54:27 -04:00
|
|
|
g.close()
|
2000-02-07 13:15:48 -04:00
|
|
|
try:
|
|
|
|
g['a']
|
|
|
|
except error:
|
|
|
|
pass
|
|
|
|
else:
|
2007-08-29 20:37:32 -03:00
|
|
|
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:
|
2007-08-29 20:37:32 -03:00
|
|
|
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
|