Add tests for token size and wrong magic number

This commit is contained in:
Piolie 2021-01-06 01:21:35 -03:00
parent 5d0ad5e2e9
commit 002e0bd697

View File

@ -49,6 +49,13 @@ def test_pnm(tmp_path):
with Image.open(f) as reloaded:
assert_image_equal(im, reloaded)
def test_not_ppm(tmp_path):
path = str(tmp_path / "temp.djvurle")
with open(path, "wb") as f:
f.write(b"PyXX")
with pytest.raises(UnidentifiedImageError):
Image.open(path)
def test_header_with_comments(tmp_path):
path = str(tmp_path / "temp.ppm")
@ -67,6 +74,13 @@ def test_nondecimal_header(tmp_path):
with pytest.raises(ValueError):
Image.open(path)
def test_token_too_long(tmp_path):
path = str(tmp_path / "temp.djvurle")
with open(path, "wb") as f:
f.write(b"P6\n 0123456789")
with pytest.raises(ValueError):
Image.open(path)
def test_truncated_file(tmp_path):
path = str(tmp_path / "temp.pgm")