]> granicus.if.org Git - python/commitdiff
Properly close files in test_dbm_dumb.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:49:14 +0000 (22:49 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:49:14 +0000 (22:49 +0000)
Lib/test/test_dbm_dumb.py

index a05db915e726a502c659b03ace7b7b356c5dbeda..6b981c429dfbf8fc62bbdbb5547fcd4c77b594bf 100644 (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')