close some more files in the tests
@@ -193,14 +193,14 @@ class Test_unpack_file_url(object):
# so we can tell it didn't get overwritten
dest_file = os.path.join(self.download_dir, self.dist_file)
copy(self.dist_path2, dest_file)
- dist_path2_md5 = hashlib.md5(
- open(self.dist_path2, 'rb').read()).hexdigest()
+ with open(self.dist_path2, 'rb') as f:
+ dist_path2_md5 = hashlib.md5(f.read()).hexdigest()
unpack_file_url(self.dist_url, self.build_dir,
download_dir=self.download_dir)
# our hash should be the same, i.e. not overwritten by simple-1.0 hash
- assert dist_path2_md5 == hashlib.md5(
- open(dest_file, 'rb').read()).hexdigest()
+ with open(dest_file, 'rb') as f:
+ assert dist_path2_md5 == hashlib.md5(f.read()).hexdigest()
def test_unpack_file_url_bad_hash(self, tmpdir, data,
monkeypatch):
@@ -227,9 +227,10 @@ class Test_unpack_file_url(object):
dest_file = os.path.join(self.download_dir, self.dist_file)
copy(self.dist_path2, dest_file)
- dist_path_md5 = hashlib.md5(
- open(self.dist_path, 'rb').read()).hexdigest()
- dist_path2_md5 = hashlib.md5(open(dest_file, 'rb').read()).hexdigest()
+ with open(self.dist_path, 'rb') as f:
+ dist_path_md5 = hashlib.md5(f.read()).hexdigest()
+ with open(dest_file, 'rb') as f:
+ dist_path2_md5 = hashlib.md5(f.read()).hexdigest()
assert dist_path_md5 != dist_path2_md5
@@ -243,9 +244,8 @@ class Test_unpack_file_url(object):
# confirm hash is for simple1-1.0
# the previous bad download has been removed
- assert (hashlib.md5(open(dest_file, 'rb').read()).hexdigest() ==
- dist_path_md5
- ), hashlib.md5(open(dest_file, 'rb').read()).hexdigest()
+ with open(dest_file, 'rb') as f:
+ assert hashlib.md5(f.read()).hexdigest() == dist_path_md5
def test_unpack_file_url_thats_a_dir(self, tmpdir, data):
self.prep(tmpdir, data)
