mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
fix 2.6 tests by replacing usages of deprecated fromstring/tostring with frombytes/tobytes
This commit is contained in:
parent
aacb8097c3
commit
c4baeccfce
|
@ -12,7 +12,7 @@ assert PIL.Image.VERSION[:3] == '1.1'
|
|||
# Create an image and do stuff with it.
|
||||
im = PIL.Image.new("1", (100, 100))
|
||||
assert (im.mode, im.size) == ('1', (100, 100))
|
||||
assert len(im.tobytes() if py3 else im.tostring()) == 1300
|
||||
assert len(im.tobytes()) == 1300
|
||||
|
||||
# Create images in all remaining major modes.
|
||||
im = PIL.Image.new("L", (100, 100))
|
||||
|
|
10
Tests/test_image_frombytes.py
Normal file
10
Tests/test_image_frombytes.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_sanity():
|
||||
im1 = lena()
|
||||
im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes())
|
||||
|
||||
assert_image_equal(im1, im2)
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
from tester import *
|
||||
|
||||
from PIL import Image
|
||||
|
||||
def test_sanity():
|
||||
|
||||
im1 = lena()
|
||||
im2 = None
|
||||
|
||||
if py3:
|
||||
im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes())
|
||||
else:
|
||||
im2 = Image.fromstring(im1.mode, im1.size, im1.tostring())
|
||||
|
||||
assert_image_equal(im1, im2)
|
||||
|
|
@ -3,5 +3,5 @@ from tester import *
|
|||
from PIL import Image
|
||||
|
||||
def test_sanity():
|
||||
data = lena().tobytes() if py3 else lena().tostring()
|
||||
data = lena().tobytes()
|
||||
assert_true(isinstance(data, bytes))
|
|
@ -16,7 +16,7 @@ def test_pack():
|
|||
if py3:
|
||||
return list(im.tobytes("raw", rawmode))
|
||||
else:
|
||||
return [ord(c) for c in im.tostring("raw", rawmode)]
|
||||
return [ord(c) for c in im.tobytes("raw", rawmode)]
|
||||
|
||||
assert_equal(pack("1", "1"), [128])
|
||||
assert_equal(pack("1", "1;I"), [0])
|
||||
|
@ -53,10 +53,10 @@ def test_unpack():
|
|||
|
||||
if py3:
|
||||
data = bytes(range(1,bytes_+1))
|
||||
im = Image.frombytes(mode, (1, 1), data, "raw", rawmode, 0, 1)
|
||||
else:
|
||||
data = ''.join(chr(i) for i in range(1,bytes_+1))
|
||||
im = Image.fromstring(mode, (1, 1), data, "raw", rawmode, 0, 1)
|
||||
|
||||
im = Image.frombytes(mode, (1, 1), data, "raw", rawmode, 0, 1)
|
||||
|
||||
return im.getpixel((0, 0))
|
||||
|
||||
|
@ -67,7 +67,7 @@ def test_unpack():
|
|||
if py3:
|
||||
im = Image.frombytes(mode, (8, 1), bytes([value]), "raw", rawmode, 0, 1)
|
||||
else:
|
||||
im = Image.fromstring(mode, (8, 1), chr(value), "raw", rawmode, 0, 1)
|
||||
im = Image.frombytes(mode, (8, 1), chr(value), "raw", rawmode, 0, 1)
|
||||
|
||||
return tuple(im.getdata())
|
||||
|
||||
|
|
|
@ -79,18 +79,15 @@ def test_basic():
|
|||
basic("I")
|
||||
|
||||
|
||||
def test_tostring():
|
||||
def test_tobytes():
|
||||
|
||||
def tostring(mode):
|
||||
if py3:
|
||||
return Image.new(mode, (1, 1), 1).tobytes()
|
||||
else:
|
||||
return Image.new(mode, (1, 1), 1).tostring()
|
||||
def tobytes(mode):
|
||||
return Image.new(mode, (1, 1), 1).tobytes()
|
||||
|
||||
assert_equal(tostring("L"), b"\x01")
|
||||
assert_equal(tostring("I;16"), b"\x01\x00")
|
||||
assert_equal(tostring("I;16B"), b"\x00\x01")
|
||||
assert_equal(tostring("I"), b"\x01\x00\x00\x00")
|
||||
assert_equal(tobytes("L"), b"\x01")
|
||||
assert_equal(tobytes("I;16"), b"\x01\x00")
|
||||
assert_equal(tobytes("I;16B"), b"\x00\x01")
|
||||
assert_equal(tobytes("I"), b"\x01\x00\x00\x00")
|
||||
|
||||
|
||||
def test_convert():
|
||||
|
|
|
@ -144,12 +144,9 @@ def assert_image_equal(a, b, msg=None):
|
|||
failure(msg or "got mode %r, expected %r" % (a.mode, b.mode))
|
||||
elif a.size != b.size:
|
||||
failure(msg or "got size %r, expected %r" % (a.size, b.size))
|
||||
elif py3 and a.tobytes() != b.tobytes():
|
||||
elif a.tobytes() != b.tobytes():
|
||||
failure(msg or "got different content")
|
||||
# generate better diff?
|
||||
elif not py3 and a.tostring() != b.tostring():
|
||||
failure(msg or "got different content")
|
||||
# same complaint?
|
||||
else:
|
||||
success()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user