Use context managers when opening images

Co-authored-by: nulano <nulano@nulano.eu>
This commit is contained in:
Andrew Murray 2020-08-03 18:47:57 +10:00 committed by GitHub
parent 0cbcae4900
commit 787cf7932d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,21 +93,24 @@ class TestImage:
assert len(Image.ID) == 0
for ext in (".jpg", ".png"):
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/hopper" + ext)
with Image.open("Tests/images/hopper" + ext):
pass
# Only JPEG
Image.init(["JPEG"])
assert len(Image.ID) != 0
Image.open("Tests/images/hopper.jpg")
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/hopper.png")
with Image.open("Tests/images/hopper.png"):
pass
finally:
# All formats
Image.init(True)
assert len(Image.ID) != 0
for ext in (".jpg", ".png"):
Image.open("Tests/images/hopper" + ext)
with Image.open("Tests/images/hopper" + ext):
pass
def test_width_height(self):
im = Image.new("RGB", (1, 2))