mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-14 09:14:45 +03:00
add roundtrip tests for image from/to bytes
This commit is contained in:
parent
f4b1244213
commit
07f6951693
|
@ -28,32 +28,32 @@ from .helper import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
all_modes = (
|
||||||
|
"1",
|
||||||
|
"P",
|
||||||
|
"PA",
|
||||||
|
"L",
|
||||||
|
"LA",
|
||||||
|
"La",
|
||||||
|
"F",
|
||||||
|
"I",
|
||||||
|
"I;16",
|
||||||
|
"I;16L",
|
||||||
|
"I;16B",
|
||||||
|
"I;16N",
|
||||||
|
"RGB",
|
||||||
|
"RGBX",
|
||||||
|
"RGBA",
|
||||||
|
"RGBa",
|
||||||
|
"CMYK",
|
||||||
|
"YCbCr",
|
||||||
|
"LAB",
|
||||||
|
"HSV",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestImage:
|
class TestImage:
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize("mode", all_modes)
|
||||||
"mode",
|
|
||||||
(
|
|
||||||
"1",
|
|
||||||
"P",
|
|
||||||
"PA",
|
|
||||||
"L",
|
|
||||||
"LA",
|
|
||||||
"La",
|
|
||||||
"F",
|
|
||||||
"I",
|
|
||||||
"I;16",
|
|
||||||
"I;16L",
|
|
||||||
"I;16B",
|
|
||||||
"I;16N",
|
|
||||||
"RGB",
|
|
||||||
"RGBX",
|
|
||||||
"RGBA",
|
|
||||||
"RGBa",
|
|
||||||
"CMYK",
|
|
||||||
"YCbCr",
|
|
||||||
"LAB",
|
|
||||||
"HSV",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
def test_image_modes_success(self, mode):
|
def test_image_modes_success(self, mode):
|
||||||
Image.new(mode, (1, 1))
|
Image.new(mode, (1, 1))
|
||||||
|
|
||||||
|
@ -862,6 +862,21 @@ class TestImage:
|
||||||
im = Image.new("RGB", size)
|
im = Image.new("RGB", size)
|
||||||
assert im.tobytes() == b""
|
assert im.tobytes() == b""
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("mode", all_modes)
|
||||||
|
def test_roundtrip_bytes_constructor(self, mode):
|
||||||
|
source_image = hopper(mode)
|
||||||
|
source_bytes = image.tobytes()
|
||||||
|
copy_image = Image.frombytes(mode, source_image.size, source_bytes)
|
||||||
|
assert copy_image.tobytes() == source_bytes
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("mode", all_modes)
|
||||||
|
def test_roundtrip_bytes_method(self, mode):
|
||||||
|
source_image = hopper(mode)
|
||||||
|
source_bytes = image.tobytes()
|
||||||
|
copy_image = Image.new(mode, source_image.size)
|
||||||
|
copy_image.frombytes(source_bytes)
|
||||||
|
assert copy_image.tobytes() == source_bytes
|
||||||
|
|
||||||
def test_apply_transparency(self):
|
def test_apply_transparency(self):
|
||||||
im = Image.new("P", (1, 1))
|
im = Image.new("P", (1, 1))
|
||||||
im.putpalette((0, 0, 0, 1, 1, 1))
|
im.putpalette((0, 0, 0, 1, 1, 1))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user