Skip to content

Commit

Permalink
add tests for image modes with a different number of bytes and bands
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Aug 1, 2024
1 parent 94b5010 commit d8012b3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Tests/test_lib_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,24 @@ def test_not_equal(mode):
img_b = Image.frombytes(mode, (2, 2), data_b)
assert img_a.tobytes() != img_b.tobytes()
assert img_a.im != img_b.im


@pytest.mark.parametrize("mode", ("RGB", "YCbCr", "HSV", "LAB"))
def test_equal_three_channels_four_bytes(mode):
# The "A" and "B" values in LAB images are signed values from -128 to 127,
# but we store them as unsigned values from 0 to 255, so we need to use
# slightly different input bytes for LAB to get the same output.
img_a = Image.new(mode, (1, 1), 0x00B3B231 if mode == "LAB" else 0x00333231)
img_b = Image.new(mode, (1, 1), 0xFFB3B231 if mode == "LAB" else 0xFF333231)
assert img_a.tobytes() == b"123"
assert img_b.tobytes() == b"123"
assert img_a.im == img_b.im


@pytest.mark.parametrize("mode", ("LA", "La", "PA"))
def test_equal_two_channels_four_bytes(mode):
img_a = Image.new(mode, (1, 1), 0x32000031)
img_b = Image.new(mode, (1, 1), 0x32FFFF31)
assert img_a.tobytes() == b"12"
assert img_b.tobytes() == b"12"
assert img_a.im == img_b.im

0 comments on commit d8012b3

Please sign in to comment.