2012-10-16 00:26:38 +04:00
|
|
|
from tester import *
|
|
|
|
|
|
|
|
from PIL import Image
|
2014-01-23 08:40:37 +04:00
|
|
|
import io
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-01-23 08:40:02 +04:00
|
|
|
def roundtrip(im):
|
|
|
|
outfile = tempfile("temp.bmp")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-01-23 08:40:02 +04:00
|
|
|
im.save(outfile, 'BMP')
|
2012-10-16 00:26:38 +04:00
|
|
|
|
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")
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
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"))
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
|
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")
|
|
|
|
|