mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +03:00
use common image mode list for TestImageGetPixel tests
This commit is contained in:
parent
5a4b771fb0
commit
0fed6a5fbc
|
@ -10,7 +10,7 @@ import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import assert_image_equal, hopper, is_win32
|
from .helper import assert_image_equal, hopper, image_mode_names, is_win32
|
||||||
|
|
||||||
# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2
|
# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2
|
||||||
# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670
|
# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670
|
||||||
|
@ -138,8 +138,8 @@ class TestImageGetPixel(AccessTest):
|
||||||
if bands == 1:
|
if bands == 1:
|
||||||
return 1
|
return 1
|
||||||
if mode in ("BGR;15", "BGR;16"):
|
if mode in ("BGR;15", "BGR;16"):
|
||||||
# These modes have less than 8 bits per band
|
# These modes have less than 8 bits per band,
|
||||||
# So (1, 2, 3) cannot be roundtripped
|
# so (1, 2, 3) cannot be roundtripped.
|
||||||
return (16, 32, 49)
|
return (16, 32, 49)
|
||||||
return tuple(range(1, bands + 1))
|
return tuple(range(1, bands + 1))
|
||||||
|
|
||||||
|
@ -168,16 +168,15 @@ class TestImageGetPixel(AccessTest):
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check 0
|
# check 0x0 image with None initial color
|
||||||
im = Image.new(mode, (0, 0), None)
|
im = Image.new(mode, (0, 0), None)
|
||||||
assert im.load() is not None
|
assert im.load() is not None
|
||||||
|
|
||||||
error = ValueError if self._need_cffi_access else IndexError
|
error = ValueError if self._need_cffi_access else IndexError
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.putpixel((0, 0), expected_color)
|
im.putpixel((0, 0), expected_color)
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.getpixel((0, 0))
|
im.getpixel((0, 0))
|
||||||
# Check 0 negative index
|
# check negative index
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.putpixel((-1, -1), expected_color)
|
im.putpixel((-1, -1), expected_color)
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
|
@ -198,36 +197,15 @@ class TestImageGetPixel(AccessTest):
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check 0
|
# check 0x0 image with initial color
|
||||||
im = Image.new(mode, (0, 0), expected_color)
|
im = Image.new(mode, (0, 0), expected_color)
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.getpixel((0, 0))
|
im.getpixel((0, 0))
|
||||||
# Check 0 negative index
|
# check negative index
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.getpixel((-1, -1))
|
im.getpixel((-1, -1))
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize("mode", image_mode_names)
|
||||||
"mode",
|
|
||||||
(
|
|
||||||
"1",
|
|
||||||
"L",
|
|
||||||
"LA",
|
|
||||||
"I",
|
|
||||||
"I;16",
|
|
||||||
"I;16B",
|
|
||||||
"F",
|
|
||||||
"P",
|
|
||||||
"PA",
|
|
||||||
"BGR;15",
|
|
||||||
"BGR;16",
|
|
||||||
"BGR;24",
|
|
||||||
"RGB",
|
|
||||||
"RGBA",
|
|
||||||
"RGBX",
|
|
||||||
"CMYK",
|
|
||||||
"YCbCr",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
def test_basic(self, mode: str) -> None:
|
def test_basic(self, mode: str) -> None:
|
||||||
self.check(mode)
|
self.check(mode)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user