From: Christian Herdtweck Date: Tue, 19 Jul 2016 11:11:11 +0000 (+0200) Subject: close a few files that are given as external fileobj to TarFile in unittests X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=124f920638e6c90056ede71c66c17ed740992633;p=python-delta-tar close a few files that are given as external fileobj to TarFile in unittests --- 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")