[Python-checkins] cpython: Properly close a file in test_os.

brett.cannon python-checkins at python.org
Tue Mar 15 22:38:30 CET 2011


http://hg.python.org/cpython/rev/9050675cb94e
changeset:   68559:9050675cb94e
user:        Brett Cannon <brett at python.org>
date:        Tue Mar 15 17:38:22 2011 -0400
summary:
  Properly close a file in test_os.

files:
  Lib/test/test_os.py

diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1528,18 +1528,16 @@
 
         def test_trailers(self):
             TESTFN2 = support.TESTFN + "2"
-            f = open(TESTFN2, 'wb')
-            f.write(b"abcde")
-            f.close()
-            f = open(TESTFN2, 'rb')
-            try:
-                os.sendfile(self.sockno, f.fileno(), 0, 4096, trailers=[b"12345"])
+            with open(TESTFN2, 'wb') as f:
+                f.write(b"abcde")
+            with open(TESTFN2, 'rb')as f:
+                self.addCleanup(os.remove, TESTFN2)
+                os.sendfile(self.sockno, f.fileno(), 0, 4096,
+                            trailers=[b"12345"])
                 self.client.close()
                 self.server.wait()
                 data = self.server.handler_instance.get_data()
                 self.assertEqual(data, b"abcde12345")
-            finally:
-                os.remove(TESTFN2)
 
         if hasattr(os, "SF_NODISKIO"):
             def test_flags(self):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list