summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gdbm.py
blob: 67c67eb6e71b3422c2e0064389fd8000ffcd3f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env python
"""Test script for the gdbm module
   Roger E. Masse
"""

import gdbm
from gdbm import error
from test_support import verbose, TestFailed

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

g.has_key('a')
g.close()
try:
    g['a']
except error:
    pass
else:
    raise TestFailed, "expected gdbm.error accessing closed database"
g = gdbm.open(filename, 'r')
g.close()
g = gdbm.open(filename, 'w')
g.close()
g = gdbm.open(filename, 'n')
g.close()
try:
    g = gdbm.open(filename, 'rx')
    g.close()
except error:
    pass
else:
    raise TestFailed, "expected gdbm.error when passing invalid open flags"

try:
    import os
    os.unlink(filename)
except:
    pass