Improve PPM tests

This commit is contained in:
Piolie 2020-12-21 01:15:49 -03:00
parent 6b81e34d67
commit 699afe1e89

View File

@ -1,6 +1,6 @@
import pytest
from PIL import Image
from PIL import Image, UnidentifiedImageError
from .helper import assert_image_equal, assert_image_similar, hopper
@ -50,12 +50,30 @@ def test_pnm(tmp_path):
assert_image_equal(im, reloaded)
def test_header_with_comments(tmp_path):
path = str(tmp_path / "temp.ppm")
with open(path, "wb") as f:
f.write(b"P6 #comment\n#comment\r12#comment\r8\n128 #comment\n255\n")
with Image.open(path) as im:
assert im.size == (128, 128)
def test_nondecimal_header(tmp_path):
path = str(tmp_path / "temp.djvurle")
with open(path, "wb") as f:
f.write(b"P6\n128\x00")
with pytest.raises(UnidentifiedImageError):
Image.open(path)
def test_truncated_file(tmp_path):
path = str(tmp_path / "temp.pgm")
with open(path, "w") as f:
f.write("P6")
with pytest.raises(ValueError):
with pytest.raises(UnidentifiedImageError):
Image.open(path)
@ -65,7 +83,7 @@ def test_neg_ppm():
# has been removed. The default opener doesn't accept negative
# sizes.
with pytest.raises(OSError):
with pytest.raises(UnidentifiedImageError):
Image.open("Tests/images/negative_size.ppm")