use hopper() for test_getdata_putdata()

This commit is contained in:
Andrew Murray 2024-04-07 22:54:47 +10:00 committed by Yay295
parent fe79ae5653
commit 5573ec7490

View File

@ -1036,17 +1036,7 @@ class TestImageBytes:
@pytest.mark.parametrize("mode", image_mode_names) @pytest.mark.parametrize("mode", image_mode_names)
def test_getdata_putdata(self, mode: str) -> None: def test_getdata_putdata(self, mode: str) -> None:
# create an image with 1 pixel to get its pixel size im = hopper(mode)
im = Image.new(mode, (1, 1))
pixel_size = len(im.tobytes())
# create a new image with incrementing byte values
im = Image.new(mode, (2, 2))
source_bytes = bytes(range(im.width * im.height * pixel_size))
im.frombytes(source_bytes)
# copy the data from the previous image to a new image
# and check that they are the same
reloaded = Image.new(mode, im.size) reloaded = Image.new(mode, im.size)
reloaded.putdata(im.getdata()) reloaded.putdata(im.getdata())
assert_image_equal(im, reloaded) assert_image_equal(im, reloaded)