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() # success()
# else: # else:
# failure(msg or "got %r, doesn't match pattern %r" % (v, pattern)) # failure(msg or "got %r, doesn't match pattern %r" % (v, pattern))
#
#
# # helpers # helpers
#
# from io import BytesIO def fromstring(data):
# from io import BytesIO
# from PIL import Image
# def fromstring(data): return Image.open(BytesIO(data))
# from PIL import Image
# return Image.open(BytesIO(data))
# def tostring(im, format, **options):
# from io import BytesIO
# def tostring(im, format, **options): out = BytesIO()
# out = BytesIO() im.save(out, format, **options)
# im.save(out, format, **options) return out.getvalue()
# return out.getvalue()
def lena(mode="RGB", cache={}): def lena(mode="RGB", cache={}):

View File

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