Skip to content

Commit 492fb69

Browse files
committed
extract mode "1" to its own test
1 parent 2204582 commit 492fb69

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Tests/test_lib_image.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import itertools
4+
35
import pytest
46

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

4648

47-
@pytest.mark.parametrize("mode", Image.MODES)
49+
# With mode "1" different bytes can map to the same value,
50+
# so we have to be more specific with the values we use.
51+
@pytest.mark.parametrize(
52+
"bytes_a, bytes_b",
53+
itertools.permutations(
54+
(bytes(x) for x in itertools.product(b"\x00\xff", repeat=4)), 2
55+
),
56+
)
57+
def test_not_equal_mode_1(bytes_a, bytes_b):
58+
# Use rawmode "1;8" so that each full byte is interpreted as a value
59+
# instead of the bits in the bytes being interpreted as values.
60+
img_a = Image.frombytes("1", (2, 2), bytes_a, "raw", "1;8")
61+
img_b = Image.frombytes("1", (2, 2), bytes_b, "raw", "1;8")
62+
assert img_a.tobytes() != img_b.tobytes()
63+
assert img_a.im != img_b.im
64+
65+
66+
@pytest.mark.parametrize("mode", [mode for mode in Image.MODES if mode != "1"])
4867
def test_not_equal(mode):
4968
num_img_bytes = len(Image.new(mode, (2, 2)).tobytes())
5069
data_a = bytes(range(ord("A"), ord("A") + num_img_bytes))

0 commit comments

Comments
 (0)