mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +03:00
Convert test_image_tobitmap.py
This commit is contained in:
parent
1f94ea1fc6
commit
34db40ddce
|
@ -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={}):
|
||||
|
|
|
@ -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__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user