Skip to content

Commit

Permalink
extract mode "1" to its own test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Jul 8, 2024
1 parent 3bd0c51 commit db9d6dc
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Tests/test_lib_image.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import itertools

import pytest

from PIL import Image
Expand Down Expand Up @@ -44,7 +46,24 @@ def test_equal(mode):
assert img_a.im == img_b.im


@pytest.mark.parametrize("mode", Image.MODES)
# With mode "1" different bytes can map to the same value,
# so we have to be more specific with the values we use.
@pytest.mark.parametrize(
"bytes_a, bytes_b",
itertools.permutations(
(bytes(x) for x in itertools.product(b"\x00\xff", repeat=4)), 2
),
)
def test_not_equal_mode_1(bytes_a, bytes_b):
# Use rawmode "1;8" so that each full byte is interpreted as a value
# instead of the bits in the bytes being interpreted as values.
img_a = Image.frombytes("1", (2, 2), bytes_a, "raw", "1;8")
img_b = Image.frombytes("1", (2, 2), bytes_b, "raw", "1;8")
assert img_a.tobytes() != img_b.tobytes()
assert img_a.im != img_b.im


@pytest.mark.parametrize("mode", [mode for mode in Image.MODES if mode != "1"])
def test_not_equal(mode):
num_img_bytes = len(Image.new(mode, (2, 2)).tobytes())
data_a = bytes(range(ord("A"), ord("A") + num_img_bytes))
Expand Down

0 comments on commit db9d6dc

Please sign in to comment.