mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929)
This commit is contained in:
parent
9e4861f523
commit
5b10b98247
25 changed files with 253 additions and 312 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue