From 124f920638e6c90056ede71c66c17ed740992633 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Tue, 19 Jul 2016 13:11:11 +0200 Subject: [PATCH] close a few files that are given as external fileobj to TarFile in unittests --- testing/test_concat_compress.py | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-) diff --git a/testing/test_concat_compress.py b/testing/test_concat_compress.py index b2539b9..729aa08 100644 --- a/testing/test_concat_compress.py +++ b/testing/test_concat_compress.py @@ -90,12 +90,11 @@ class ConcatCompressTest(BaseTest): tarobj.close() os.unlink("big") - fo = open("sample.tar.gz", 'rb') # will not be released on tarfile.close() - fo.seek(pos) - tarobj = TarFile.open(mode="r#gz", fileobj=fo) - tarobj.extract(tarobj.next()) - tarobj.close() - fo.close() + with open("sample.tar.gz", 'rb') as fo: + fo.seek(pos) + tarobj = TarFile.open(mode="r#gz", fileobj=fo) + tarobj.extract(tarobj.next()) + tarobj.close() assert os.path.exists("big") assert hash == self.md5sum("big") @@ -127,12 +126,11 @@ class ConcatCompressTest(BaseTest): os.unlink("small2") # extract only the "small" file - fo = open("sample.tar.gz", 'rb') # will not be released on tarfile.close() - fo.seek(pos) - tarobj = TarFile.open(mode="r#gz", fileobj=fo) - tarobj.extract(tarobj.next()) - tarobj.close() - fo.close() + with open("sample.tar.gz", 'rb') as fo: + fo.seek(pos) + tarobj = TarFile.open(mode="r#gz", fileobj=fo) + tarobj.extract(tarobj.next()) + tarobj.close() assert os.path.exists("small") assert hash['small'] == self.md5sum("small") -- 1.7.1