Commit e7629c85 authored by Neal Norwitz's avatar Neal Norwitz

Skip test_dbm if we can't write to the file

Cleanup (remove) the file(s) after we are done with the test.
(Fixes problem on snake farm)
parent 94a83fdc
...@@ -2,42 +2,54 @@ ...@@ -2,42 +2,54 @@
"""Test script for the dbm module """Test script for the dbm module
Roger E. Masse Roger E. Masse
""" """
import os
import random
import dbm import dbm
from dbm import error from dbm import error
from test.test_support import verbose, verify from test.test_support import verbose, verify, TestSkipped
filename = '/tmp/delete_me' # make filename unique to allow multiple concurrent tests
# and to minimize the likelihood of a problem from an old file
filename = '/tmp/delete_me_' + str(random.random())[-6:]
d = dbm.open(filename, 'c') def cleanup():
verify(d.keys() == []) for suffix in ['', '.pag', '.dir', '.db']:
d['a'] = 'b' try:
d['12345678910'] = '019237410982340912840198242' os.unlink(filename + suffix)
d.keys() except OSError, (errno, strerror):
if d.has_key('a'): # if we can't delete the file because of permissions,
if verbose: # nothing will work, so skip the test
print 'Test dbm keys: ', d.keys() if errno == 1:
raise TestSkipped, 'unable to remove: ' + filename + suffix
d.close() def test_keys():
d = dbm.open(filename, 'r') d = dbm.open(filename, 'c')
d.close() verify(d.keys() == [])
d = dbm.open(filename, 'rw') d['a'] = 'b'
d.close() d['12345678910'] = '019237410982340912840198242'
d = dbm.open(filename, 'w') d.keys()
d.close() if d.has_key('a'):
d = dbm.open(filename, 'n') if verbose:
d.close() print 'Test dbm keys: ', d.keys()
d.close()
def test_modes():
d = dbm.open(filename, 'r')
d.close()
d = dbm.open(filename, 'rw')
d.close()
d = dbm.open(filename, 'w')
d.close()
d = dbm.open(filename, 'n')
d.close()
cleanup()
try: try:
import os test_keys()
if dbm.library == "ndbm": test_modes()
# classic dbm
os.unlink(filename + '.dir')
os.unlink(filename + '.pag')
elif dbm.library == "BSD db":
# BSD DB's compatibility layer
os.unlink(filename + '.db')
else:
# GNU gdbm compatibility layer
os.unlink(filename)
except: except:
pass cleanup()
raise
cleanup()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment