bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929)

This commit is contained in:
Serhiy Storchaka 2019-03-05 10:06:26 +02:00 committed by GitHub
parent 9e4861f523
commit 5b10b98247
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 253 additions and 312 deletions

View file

@ -23,17 +23,15 @@ class BinHexTestCase(unittest.TestCase):
DATA = b'Jack is my hero'
def test_binhex(self):
f = open(self.fname1, 'wb')
f.write(self.DATA)
f.close()
with open(self.fname1, 'wb') as f:
f.write(self.DATA)
binhex.binhex(self.fname1, self.fname2)
binhex.hexbin(self.fname2, self.fname1)
f = open(self.fname1, 'rb')
finish = f.readline()
f.close()
with open(self.fname1, 'rb') as f:
finish = f.readline()
self.assertEqual(self.DATA, finish)