]> granicus.if.org Git - python/commitdiff
have test_asyncore properly close files.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:40:44 +0000 (22:40 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Oct 2010 22:40:44 +0000 (22:40 +0000)
Lib/test/test_asyncore.py

index f2ec8b86c80b8fb3b85a4b8a8e7b804240a6f387..545046825257da85e54c8679f08ce9e04146b40c 100644 (file)
@@ -397,7 +397,8 @@ class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests):
 class FileWrapperTest(unittest.TestCase):
     def setUp(self):
         self.d = b"It's not dead, it's sleeping!"
-        open(TESTFN, 'wb').write(self.d)
+        with open(TESTFN, 'wb') as file:
+            file.write(self.d)
 
     def tearDown(self):
         unlink(TESTFN)
@@ -424,7 +425,8 @@ class FileWrapperTest(unittest.TestCase):
         w.write(d1)
         w.send(d2)
         w.close()
-        self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
+        with open(TESTFN, 'rb') as file:
+            self.assertEqual(file.read(), self.d + d1 + d2)
 
     @unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
                          'asyncore.file_dispatcher required')