Skip to content

Commit

Permalink
Added IMT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 28, 2022
1 parent aa8877a commit a2ced61
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Binary file added Tests/images/hopper.imt
Binary file not shown.
19 changes: 19 additions & 0 deletions Tests/test_file_imt.py
@@ -0,0 +1,19 @@
import io

import pytest

from PIL import Image, ImtImagePlugin

from .helper import assert_image_equal_tofile


def test_sanity():
with Image.open("Tests/images/hopper.imt") as im:
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")


@pytest.mark.parametrize("data", (b"\n", b"\n-", b"width 1\n"))
def test_invalid_file(data):
with io.BytesIO(data) as fp:
with pytest.raises(SyntaxError):
ImtImagePlugin.ImtImageFile(fp)
6 changes: 3 additions & 3 deletions src/PIL/ImtImagePlugin.py
Expand Up @@ -74,13 +74,13 @@ def _open(self):
if not m:
break
k, v = m.group(1, 2)
if k == "width":
if k == b"width":
xsize = int(v)
self._size = xsize, ysize
elif k == "height":
elif k == b"height":
ysize = int(v)
self._size = xsize, ysize
elif k == "pixel" and v == "n8":
elif k == b"pixel" and v == b"n8":
self.mode = "L"


Expand Down

0 comments on commit a2ced61

Please sign in to comment.