mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-22 21:24:46 +03:00
Use context managers when opening images
Co-authored-by: nulano <nulano@nulano.eu>
This commit is contained in:
parent
0cbcae4900
commit
787cf7932d
|
@ -93,21 +93,24 @@ class TestImage:
|
||||||
assert len(Image.ID) == 0
|
assert len(Image.ID) == 0
|
||||||
for ext in (".jpg", ".png"):
|
for ext in (".jpg", ".png"):
|
||||||
with pytest.raises(UnidentifiedImageError):
|
with pytest.raises(UnidentifiedImageError):
|
||||||
Image.open("Tests/images/hopper" + ext)
|
with Image.open("Tests/images/hopper" + ext):
|
||||||
|
pass
|
||||||
|
|
||||||
# Only JPEG
|
# Only JPEG
|
||||||
Image.init(["JPEG"])
|
Image.init(["JPEG"])
|
||||||
assert len(Image.ID) != 0
|
assert len(Image.ID) != 0
|
||||||
Image.open("Tests/images/hopper.jpg")
|
Image.open("Tests/images/hopper.jpg")
|
||||||
with pytest.raises(UnidentifiedImageError):
|
with pytest.raises(UnidentifiedImageError):
|
||||||
Image.open("Tests/images/hopper.png")
|
with Image.open("Tests/images/hopper.png"):
|
||||||
|
pass
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# All formats
|
# All formats
|
||||||
Image.init(True)
|
Image.init(True)
|
||||||
assert len(Image.ID) != 0
|
assert len(Image.ID) != 0
|
||||||
for ext in (".jpg", ".png"):
|
for ext in (".jpg", ".png"):
|
||||||
Image.open("Tests/images/hopper" + ext)
|
with Image.open("Tests/images/hopper" + ext):
|
||||||
|
pass
|
||||||
|
|
||||||
def test_width_height(self):
|
def test_width_height(self):
|
||||||
im = Image.new("RGB", (1, 2))
|
im = Image.new("RGB", (1, 2))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user