Pillow/Tests/test_file_bmp.py

39 lines
751 B
Python
Raw Normal View History

from tester import *
from PIL import Image
2014-01-23 08:40:37 +04:00
import io
2014-01-23 08:40:02 +04:00
def roundtrip(im):
outfile = tempfile("temp.bmp")
2014-01-23 08:40:02 +04:00
im.save(outfile, 'BMP')
2014-01-23 08:40:02 +04:00
reloaded = Image.open(outfile)
reloaded.load()
assert_equal(im.mode, reloaded.mode)
assert_equal(im.size, reloaded.size)
assert_equal(reloaded.format, "BMP")
2014-01-23 08:40:02 +04:00
def test_sanity():
roundtrip(lena())
roundtrip(lena("1"))
roundtrip(lena("L"))
roundtrip(lena("P"))
roundtrip(lena("RGB"))
2014-01-23 08:40:37 +04:00
def test_save_to_bytes():
output = io.BytesIO()
im = lena()
im.save(output, "BMP")
output.seek(0)
reloaded = Image.open(output)
assert_equal(im.mode, reloaded.mode)
assert_equal(im.size, reloaded.size)
assert_equal(reloaded.format, "BMP")