mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-09-21 03:18:57 +03:00
Improve PPM tests
This commit is contained in:
parent
6b81e34d67
commit
699afe1e89
|
@ -1,6 +1,6 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
|
||||||
from .helper import assert_image_equal, assert_image_similar, hopper
|
from .helper import assert_image_equal, assert_image_similar, hopper
|
||||||
|
|
||||||
|
@ -50,12 +50,30 @@ def test_pnm(tmp_path):
|
||||||
assert_image_equal(im, reloaded)
|
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):
|
def test_truncated_file(tmp_path):
|
||||||
path = str(tmp_path / "temp.pgm")
|
path = str(tmp_path / "temp.pgm")
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
f.write("P6")
|
f.write("P6")
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(UnidentifiedImageError):
|
||||||
Image.open(path)
|
Image.open(path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +83,7 @@ def test_neg_ppm():
|
||||||
# has been removed. The default opener doesn't accept negative
|
# has been removed. The default opener doesn't accept negative
|
||||||
# sizes.
|
# sizes.
|
||||||
|
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(UnidentifiedImageError):
|
||||||
Image.open("Tests/images/negative_size.ppm")
|
Image.open("Tests/images/negative_size.ppm")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user