Pillow/Tests/test_file_xbm.py

83 lines
2.0 KiB
Python
Raw Normal View History

from io import BytesIO
2020-01-27 14:46:52 +03:00
import pytest
from PIL import Image
2020-01-27 14:46:52 +03:00
from .helper import hopper
PIL151 = b"""
#define basic_width 32
#define basic_height 32
static char basic_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x80, 0xff, 0xff, 0x01, 0x40, 0x00, 0x00, 0x02,
0x20, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08,
0x20, 0x00, 0x00, 0x04,
0x20, 0x00, 0x00, 0x04, 0x40, 0x00, 0x00, 0x02,
0x80, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
"""
2020-01-27 14:46:52 +03:00
def test_pil151():
with Image.open(BytesIO(PIL151)) as im:
im.load()
assert im.mode == "1"
assert im.size == (32, 32)
2014-06-10 13:10:47 +04:00
2020-01-27 14:46:52 +03:00
def test_open():
# Arrange
# Created with `convert hopper.png hopper.xbm`
filename = "Tests/images/hopper.xbm"
2020-01-27 14:46:52 +03:00
# Act
with Image.open(filename) as im:
2020-01-27 14:46:52 +03:00
# Assert
assert im.mode == "1"
assert im.size == (128, 128)
2020-01-27 14:46:52 +03:00
def test_open_filename_with_underscore():
# Arrange
# Created with `convert hopper.png hopper_underscore.xbm`
filename = "Tests/images/hopper_underscore.xbm"
2020-01-14 12:51:56 +03:00
2020-01-27 14:46:52 +03:00
# Act
with Image.open(filename) as im:
2020-01-14 12:51:56 +03:00
2020-01-27 14:46:52 +03:00
# Assert
assert im.mode == "1"
assert im.size == (128, 128)
2020-01-14 13:10:10 +03:00
2020-01-27 14:46:52 +03:00
def test_save_wrong_mode(tmp_path):
im = hopper()
out = str(tmp_path / "temp.xbm")
2020-01-14 13:10:10 +03:00
2020-01-27 14:46:52 +03:00
with pytest.raises(OSError):
im.save(out)
def test_hotspot(tmp_path):
im = hopper("1")
out = str(tmp_path / "temp.xbm")
hotspot = (0, 7)
im.save(out, hotspot=hotspot)
with Image.open(out) as reloaded:
assert reloaded.info["hotspot"] == hotspot