Convert test_image_tobitmap.py

This commit is contained in:
hugovk 2014-06-05 12:39:15 +03:00
parent 1f94ea1fc6
commit 34db40ddce
2 changed files with 23 additions and 26 deletions

View File

@ -129,22 +129,21 @@ py3 = (sys.version_info >= (3, 0))
# success()
# else:
# failure(msg or "got %r, doesn't match pattern %r" % (v, pattern))
#
#
# # helpers
#
# from io import BytesIO
#
#
# def fromstring(data):
# from PIL import Image
# return Image.open(BytesIO(data))
#
#
# def tostring(im, format, **options):
# out = BytesIO()
# im.save(out, format, **options)
# return out.getvalue()
# helpers
def fromstring(data):
from io import BytesIO
from PIL import Image
return Image.open(BytesIO(data))
def tostring(im, format, **options):
from io import BytesIO
out = BytesIO()
im.save(out, format, **options)
return out.getvalue()
def lena(mode="RGB", cache={}):

View File

@ -1,21 +1,19 @@
from helper import unittest, PillowTestCase, lena
from PIL import Image
from helper import unittest, PillowTestCase, lena, fromstring
class TestImage(PillowTestCase):
def test_sanity(self):
def test_sanity(self):
self.assertRaises(ValueError, lambda: lena().tobitmap())
assert_no_exception(lambda: lena().convert("1").tobitmap())
self.assertRaises(ValueError, lambda: lena().tobitmap())
lena().convert("1").tobitmap()
im1 = lena().convert("1")
im1 = lena().convert("1")
bitmap = im1.tobitmap()
bitmap = im1.tobitmap()
assert_true(isinstance(bitmap, bytes))
assert_image_equal(im1, fromstring(bitmap))
self.assertIsInstance(bitmap, bytes)
self.assert_image_equal(im1, fromstring(bitmap))
if __name__ == '__main__':