mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-17 19:52:35 +03:00
Merge pull request #805 from hugovk/DcxImagePlugin
Tests for CurImagePlugin.py and DcxImagePlugin.py
This commit is contained in:
commit
c0e840f242
|
@ -33,6 +33,7 @@ i32 = _binary.i32le
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[:4] == b"\0\0\2\0"
|
return prefix[:4] == b"\0\0\2\0"
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for Windows Cursor files.
|
# Image plugin for Windows Cursor files.
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
# check magic
|
# check magic
|
||||||
s = self.fp.read(6)
|
s = self.fp.read(6)
|
||||||
if not _accept(s):
|
if not _accept(s):
|
||||||
raise SyntaxError("not an CUR file")
|
raise SyntaxError("not a CUR file")
|
||||||
|
|
||||||
# pick the largest cursor in the file
|
# pick the largest cursor in the file
|
||||||
m = b""
|
m = b""
|
||||||
|
|
|
@ -31,9 +31,11 @@ MAGIC = 0x3ADE68B1 # QUIZ: what's this value, then?
|
||||||
|
|
||||||
i32 = _binary.i32le
|
i32 = _binary.i32le
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return i32(prefix) == MAGIC
|
return i32(prefix) == MAGIC
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Image plugin for the Intel DCX format.
|
# Image plugin for the Intel DCX format.
|
||||||
|
|
||||||
|
|
BIN
Tests/images/deerstalker.cur
Normal file
BIN
Tests/images/deerstalker.cur
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
BIN
Tests/images/lena.dcx
Normal file
BIN
Tests/images/lena.dcx
Normal file
Binary file not shown.
27
Tests/test_file_cur.py
Normal file
27
Tests/test_file_cur.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
|
from PIL import Image, CurImagePlugin
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileCur(PillowTestCase):
|
||||||
|
|
||||||
|
def test_sanity(self):
|
||||||
|
# Arrange
|
||||||
|
test_file = "Tests/images/deerstalker.cur"
|
||||||
|
|
||||||
|
# Act
|
||||||
|
im = Image.open(test_file)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(im.size, (32, 32))
|
||||||
|
self.assertIsInstance(im, CurImagePlugin.CurImageFile)
|
||||||
|
# Check some pixel colors to ensure image is loaded properly
|
||||||
|
self.assertEqual(im.getpixel((10, 1)), (0, 0, 0))
|
||||||
|
self.assertEqual(im.getpixel((11, 1)), (253, 254, 254))
|
||||||
|
self.assertEqual(im.getpixel((16, 16)), (84, 87, 86))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
# End of file
|
45
Tests/test_file_dcx.py
Normal file
45
Tests/test_file_dcx.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
from helper import unittest, PillowTestCase, lena
|
||||||
|
|
||||||
|
from PIL import Image, DcxImagePlugin
|
||||||
|
|
||||||
|
# Created with ImageMagick: convert lena.ppm lena.dcx
|
||||||
|
TEST_FILE = "Tests/images/lena.dcx"
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileDcx(PillowTestCase):
|
||||||
|
|
||||||
|
def test_sanity(self):
|
||||||
|
# Arrange
|
||||||
|
|
||||||
|
# Act
|
||||||
|
im = Image.open(TEST_FILE)
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(im.size, (128, 128))
|
||||||
|
self.assertIsInstance(im, DcxImagePlugin.DcxImageFile)
|
||||||
|
orig = lena()
|
||||||
|
self.assert_image_equal(im, orig)
|
||||||
|
|
||||||
|
def test_tell(self):
|
||||||
|
# Arrange
|
||||||
|
im = Image.open(TEST_FILE)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
frame = im.tell()
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
self.assertEqual(frame, 0)
|
||||||
|
|
||||||
|
def test_seek_too_far(self):
|
||||||
|
# Arrange
|
||||||
|
im = Image.open(TEST_FILE)
|
||||||
|
frame = 999 # too big on purpose
|
||||||
|
|
||||||
|
# Act / Assert
|
||||||
|
self.assertRaises(EOFError, lambda: im.seek(frame))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
# End of file
|
Loading…
Reference in New Issue
Block a user