Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 481c6dd

Browse files
Issue #18919: Fixed resource leaks in audio tests.
2 parents 1f56a94 + 85812bc commit 481c6dd

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/test/audiotests.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,18 @@ def test_read_params(self):
191191
self.sndfilenframes, self.comptype, self.compname)
192192

193193
def test_close(self):
194-
testfile = open(self.sndfilepath, 'rb')
195-
f = self.f = self.module.open(testfile)
196-
self.assertFalse(testfile.closed)
197-
f.close()
198-
self.assertEqual(testfile.closed, self.close_fd)
199-
testfile = open(TESTFN, 'wb')
200-
fout = self.module.open(testfile, 'wb')
201-
self.assertFalse(testfile.closed)
202-
with self.assertRaises(self.module.Error):
203-
fout.close()
204-
self.assertEqual(testfile.closed, self.close_fd)
205-
fout.close() # do nothing
194+
with open(self.sndfilepath, 'rb') as testfile:
195+
f = self.f = self.module.open(testfile)
196+
self.assertFalse(testfile.closed)
197+
f.close()
198+
self.assertEqual(testfile.closed, self.close_fd)
199+
with open(TESTFN, 'wb') as testfile:
200+
fout = self.fout = self.module.open(testfile, 'wb')
201+
self.assertFalse(testfile.closed)
202+
with self.assertRaises(self.module.Error):
203+
fout.close()
204+
self.assertEqual(testfile.closed, self.close_fd)
205+
fout.close() # do nothing
206206

207207
def test_read(self):
208208
framesize = self.nchannels * self.sampwidth

0 commit comments

Comments
 (0)