Skip to content

Commit

Permalink
Parametrized test
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 30, 2021
1 parent eab2b17 commit 8f5762e
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions Tests/test_imagepalette.py
Expand Up @@ -49,23 +49,27 @@ def test_getcolor():
palette.getcolor("unknown")


def test_getcolor_not_special():
im = Image.new("P", (1, 1))
for index, palette in {
@pytest.mark.parametrize(
"index, palette",
[
# Test when the palette is not full
0: ImagePalette.ImagePalette(),
(0, ImagePalette.ImagePalette()),
# Test when the palette is full
255: ImagePalette.ImagePalette("RGB", list(range(256)) * 3),
}.items():
# Do not use transparency index as a new color
im.info["transparency"] = index
index1 = palette.getcolor((0, 0, 0), im)
assert index1 != index

# Do not use background index as a new color
im.info["background"] = index1
index2 = palette.getcolor((0, 0, 1), im)
assert index2 not in (index, index1)
(255, ImagePalette.ImagePalette("RGB", list(range(256)) * 3)),
],
)
def test_getcolor_not_special(index, palette):
im = Image.new("P", (1, 1))

# Do not use transparency index as a new color
im.info["transparency"] = index
index1 = palette.getcolor((0, 0, 0), im)
assert index1 != index

# Do not use background index as a new color
im.info["background"] = index1
index2 = palette.getcolor((0, 0, 1), im)
assert index2 not in (index, index1)


def test_file(tmp_path):
Expand Down

0 comments on commit 8f5762e

Please sign in to comment.