Pillow/Tests/test_file_cur.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

34 lines
962 B
Python
Raw Normal View History

from __future__ import annotations
2024-01-20 14:23:03 +03:00
2020-01-27 14:46:52 +03:00
import pytest
from PIL import CurImagePlugin, Image
2014-07-17 00:45:18 +04:00
TEST_FILE = "Tests/images/deerstalker.cur"
2014-07-17 00:45:18 +04:00
2024-01-27 07:19:43 +03:00
def test_sanity() -> None:
2020-01-27 14:46:52 +03:00
with Image.open(TEST_FILE) as im:
assert im.size == (32, 32)
assert isinstance(im, CurImagePlugin.CurImageFile)
# Check some pixel colors to ensure image is loaded properly
assert im.getpixel((10, 1)) == (0, 0, 0, 0)
assert im.getpixel((11, 1)) == (253, 254, 254, 1)
assert im.getpixel((16, 16)) == (84, 87, 86, 255)
2014-07-17 00:45:18 +04:00
2024-01-27 07:19:43 +03:00
def test_invalid_file() -> None:
2020-01-27 14:46:52 +03:00
invalid_file = "Tests/images/flower.jpg"
2015-07-03 09:22:56 +03:00
2020-01-27 14:46:52 +03:00
with pytest.raises(SyntaxError):
CurImagePlugin.CurImageFile(invalid_file)
2015-07-03 08:03:25 +03:00
2020-01-27 14:46:52 +03:00
no_cursors_file = "Tests/images/no_cursors.cur"
2020-01-27 14:46:52 +03:00
cur = CurImagePlugin.CurImageFile(TEST_FILE)
2024-09-09 15:34:46 +03:00
assert cur.fp is not None
2020-01-27 14:46:52 +03:00
cur.fp.close()
with open(no_cursors_file, "rb") as cur.fp:
with pytest.raises(TypeError):
cur._open()