0001 #! /usr/bin/env python 0002 """Test script for the dbm module 0003 Roger E. Masse 0004 """ 0005 import os 0006 import random 0007 import dbm 0008 from dbm import error 0009 from test.test_support import verbose, verify, TestSkipped 0010 0011 # make filename unique to allow multiple concurrent tests 0012 # and to minimize the likelihood of a problem from an old file 0013 filename = '/tmp/delete_me_' + str(random.random())[-6:] 0014 0015 def cleanup(): 0016 for suffix in ['', '.pag', '.dir', '.db']: 0017 try: 0018 os.unlink(filename + suffix) 0019 except OSError, (errno, strerror): 0020 # if we can't delete the file because of permissions, 0021 # nothing will work, so skip the test 0022 if errno == 1: 0023 raise TestSkipped, 'unable to remove: ' + filename + suffix 0024 0025 def test_keys(): 0026 d = dbm.open(filename, 'c') 0027 verify(d.keys() == []) 0028 d['a'] = 'b' 0029 d['12345678910'] = '019237410982340912840198242' 0030 d.keys() 0031 if d.has_key('a'): 0032 if verbose: 0033 print 'Test dbm keys: ', d.keys() 0034 0035 d.close() 0036 0037 def test_modes(): 0038 d = dbm.open(filename, 'r') 0039 d.close() 0040 d = dbm.open(filename, 'rw') 0041 d.close() 0042 d = dbm.open(filename, 'w') 0043 d.close() 0044 d = dbm.open(filename, 'n') 0045 d.close() 0046 0047 cleanup() 0048 try: 0049 test_keys() 0050 test_modes() 0051 except: 0052 cleanup() 0053 raise 0054 0055 cleanup() 0056
Generated by PyXR 0.9.4