Properly close files in test_dbm_dumb.

This commit is contained in:
Brett Cannon 2010-10-29 22:49:14 +00:00
parent 5ede149342
commit c0eee315f5
1 changed files with 4 additions and 2 deletions

View File

@ -132,12 +132,14 @@ class DumbDBMTestCase(unittest.TestCase):
f.close()
# Mangle the file by changing the line separator to Windows or Unix
data = io.open(_fname + '.dir', 'rb').read()
with io.open(_fname + '.dir', 'rb') as file:
data = file.read()
if os.linesep == '\n':
data = data.replace(b'\n', b'\r\n')
else:
data = data.replace(b'\r\n', b'\n')
io.open(_fname + '.dir', 'wb').write(data)
with io.open(_fname + '.dir', 'wb') as file:
file.write(data)
f = dumbdbm.open(_fname)
self.assertEqual(f[b'1'], b'hello')