[Python-checkins] cpython (merge 3.3 -> default): Issue #18919: Fixed resource leaks in audio tests.

serhiy.storchaka python-checkins at python.org
Mon Oct 14 19:10:45 CEST 2013


http://hg.python.org/cpython/rev/835c6ea487b1
changeset:   86372:835c6ea487b1
parent:      86369:d168f094d16d
parent:      86371:2850fc02f324
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Mon Oct 14 20:10:18 2013 +0300
summary:
  Issue #18919: Fixed resource leaks in audio tests.

files:
  Lib/test/audiotests.py |  24 ++++++++++++------------
  1 files changed, 12 insertions(+), 12 deletions(-)


diff --git a/Lib/test/audiotests.py b/Lib/test/audiotests.py
--- a/Lib/test/audiotests.py
+++ b/Lib/test/audiotests.py
@@ -191,18 +191,18 @@
                           self.sndfilenframes, self.comptype, self.compname)
 
     def test_close(self):
-        testfile = open(self.sndfilepath, 'rb')
-        f = self.f = self.module.open(testfile)
-        self.assertFalse(testfile.closed)
-        f.close()
-        self.assertEqual(testfile.closed, self.close_fd)
-        testfile = open(TESTFN, 'wb')
-        fout = self.module.open(testfile, 'wb')
-        self.assertFalse(testfile.closed)
-        with self.assertRaises(self.module.Error):
-            fout.close()
-        self.assertEqual(testfile.closed, self.close_fd)
-        fout.close() # do nothing
+        with open(self.sndfilepath, 'rb') as testfile:
+            f = self.f = self.module.open(testfile)
+            self.assertFalse(testfile.closed)
+            f.close()
+            self.assertEqual(testfile.closed, self.close_fd)
+        with open(TESTFN, 'wb') as testfile:
+            fout = self.fout = self.module.open(testfile, 'wb')
+            self.assertFalse(testfile.closed)
+            with self.assertRaises(self.module.Error):
+                fout.close()
+            self.assertEqual(testfile.closed, self.close_fd)
+            fout.close() # do nothing
 
     def test_read(self):
         framesize = self.nchannels * self.sampwidth

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


More information about the Python-checkins mailing list