mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-13 16:54: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:
|
||||
@pytest.mark.parametrize(
|
||||
"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",
|
||||
),
|
||||
)
|
||||
@pytest.mark.parametrize("mode", all_modes)
|
||||
def test_image_modes_success(self, mode):
|
||||
Image.new(mode, (1, 1))
|
||||
|
||||
|
@ -862,6 +862,21 @@ class TestImage:
|
|||
im = Image.new("RGB", size)
|
||||
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):
|
||||
im = Image.new("P", (1, 1))
|
||||
im.putpalette((0, 0, 0, 1, 1, 1))
|
||||
|
|
Loading…
Reference in New Issue
Block a user