mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Raise SyntaxError if data is not as expected
This commit is contained in:
parent
fbaaf3c19b
commit
efb9d503a7
|
@ -2,7 +2,7 @@ from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image, XbmImagePlugin
|
||||||
|
|
||||||
from .helper import hopper
|
from .helper import hopper
|
||||||
|
|
||||||
|
@ -63,6 +63,13 @@ def test_open_filename_with_underscore():
|
||||||
assert im.size == (128, 128)
|
assert im.size == (128, 128)
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_file():
|
||||||
|
invalid_file = "Tests/images/flower.jpg"
|
||||||
|
|
||||||
|
with pytest.raises(SyntaxError):
|
||||||
|
XbmImagePlugin.XbmImageFile(invalid_file)
|
||||||
|
|
||||||
|
|
||||||
def test_save_wrong_mode(tmp_path):
|
def test_save_wrong_mode(tmp_path):
|
||||||
im = hopper()
|
im = hopper()
|
||||||
out = str(tmp_path / "temp.xbm")
|
out = str(tmp_path / "temp.xbm")
|
||||||
|
|
|
@ -52,7 +52,8 @@ class XbmImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
m = xbm_head.match(self.fp.read(512))
|
m = xbm_head.match(self.fp.read(512))
|
||||||
|
|
||||||
if m:
|
if not m:
|
||||||
|
raise SyntaxError("not a XBM file")
|
||||||
|
|
||||||
xsize = int(m.group("width"))
|
xsize = int(m.group("width"))
|
||||||
ysize = int(m.group("height"))
|
ysize = int(m.group("height"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user