mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 02:16:19 +03:00
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
from io import BytesIO
|
|
|
|
from PIL import Image
|
|
|
|
from .helper import PillowTestCase, 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,
|
|
};
|
|
"""
|
|
|
|
|
|
class TestFileXbm(PillowTestCase):
|
|
def test_pil151(self):
|
|
with Image.open(BytesIO(PIL151)) as im:
|
|
im.load()
|
|
self.assertEqual(im.mode, "1")
|
|
self.assertEqual(im.size, (32, 32))
|
|
|
|
def test_open(self):
|
|
# Arrange
|
|
# Created with `convert hopper.png hopper.xbm`
|
|
filename = "Tests/images/hopper.xbm"
|
|
|
|
# Act
|
|
with Image.open(filename) as im:
|
|
|
|
# Assert
|
|
self.assertEqual(im.mode, "1")
|
|
self.assertEqual(im.size, (128, 128))
|
|
|
|
def test_open_filename_with_underscore(self):
|
|
# Arrange
|
|
# Created with `convert hopper.png hopper_underscore.xbm`
|
|
filename = "Tests/images/hopper_underscore.xbm"
|
|
|
|
# Act
|
|
with Image.open(filename) as im:
|
|
|
|
# Assert
|
|
self.assertEqual(im.mode, "1")
|
|
self.assertEqual(im.size, (128, 128))
|
|
|
|
def test_save_wrong_mode(self):
|
|
im = hopper()
|
|
out = self.tempfile("temp.xbm")
|
|
|
|
with self.assertRaises(OSError):
|
|
im.save(out)
|
|
|
|
def test_hotspot(self):
|
|
im = hopper("1")
|
|
out = self.tempfile("temp.xbm")
|
|
|
|
hotspot = (0, 7)
|
|
im.save(out, hotspot=hotspot)
|
|
|
|
with Image.open(out) as reloaded:
|
|
self.assertEqual(reloaded.info["hotspot"], hotspot)
|