mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
clean up comments in test_image_access.py
This commit is contained in:
parent
5faebadd56
commit
a4080a7249
|
@ -33,7 +33,7 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
class AccessTest:
|
class AccessTest:
|
||||||
# initial value
|
# Initial value
|
||||||
_init_cffi_access = Image.USE_CFFI_ACCESS
|
_init_cffi_access = Image.USE_CFFI_ACCESS
|
||||||
_need_cffi_access = False
|
_need_cffi_access = False
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class TestImageGetPixel(AccessTest):
|
||||||
self.color(mode) if expected_color_int is None else expected_color_int
|
self.color(mode) if expected_color_int is None else expected_color_int
|
||||||
)
|
)
|
||||||
|
|
||||||
# check putpixel
|
# Check putpixel
|
||||||
im = Image.new(mode, (1, 1), None)
|
im = Image.new(mode, (1, 1), None)
|
||||||
im.putpixel((0, 0), expected_color)
|
im.putpixel((0, 0), expected_color)
|
||||||
actual_color = im.getpixel((0, 0))
|
actual_color = im.getpixel((0, 0))
|
||||||
|
@ -160,7 +160,7 @@ class TestImageGetPixel(AccessTest):
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# check putpixel negative index
|
# Check putpixel negative index
|
||||||
im.putpixel((-1, -1), expected_color)
|
im.putpixel((-1, -1), expected_color)
|
||||||
actual_color = im.getpixel((-1, -1))
|
actual_color = im.getpixel((-1, -1))
|
||||||
assert actual_color == expected_color, (
|
assert actual_color == expected_color, (
|
||||||
|
@ -168,7 +168,7 @@ class TestImageGetPixel(AccessTest):
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# check 0x0 image with None initial color
|
# 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
|
||||||
|
@ -176,13 +176,13 @@ class TestImageGetPixel(AccessTest):
|
||||||
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 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):
|
||||||
im.getpixel((-1, -1))
|
im.getpixel((-1, -1))
|
||||||
|
|
||||||
# check initial color
|
# Check initial color
|
||||||
im = Image.new(mode, (1, 1), expected_color)
|
im = Image.new(mode, (1, 1), expected_color)
|
||||||
actual_color = im.getpixel((0, 0))
|
actual_color = im.getpixel((0, 0))
|
||||||
assert actual_color == expected_color, (
|
assert actual_color == expected_color, (
|
||||||
|
@ -190,18 +190,18 @@ class TestImageGetPixel(AccessTest):
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# check initial color negative index
|
# Check initial color negative index
|
||||||
actual_color = im.getpixel((-1, -1))
|
actual_color = im.getpixel((-1, -1))
|
||||||
assert actual_color == expected_color, (
|
assert actual_color == expected_color, (
|
||||||
f"initial color failed with negative index for mode {mode}, "
|
f"initial color failed with negative index for mode {mode}, "
|
||||||
f"expected {expected_color} got {actual_color}"
|
f"expected {expected_color} got {actual_color}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# check 0x0 image with initial color
|
# 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 negative index
|
# Check negative index
|
||||||
with pytest.raises(error):
|
with pytest.raises(error):
|
||||||
im.getpixel((-1, -1))
|
im.getpixel((-1, -1))
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ class TestImageGetPixel(AccessTest):
|
||||||
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
|
@pytest.mark.parametrize("mode", ("I;16", "I;16B"))
|
||||||
@pytest.mark.parametrize("expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1))
|
@pytest.mark.parametrize("expected_color", (2**15 - 1, 2**15, 2**15 + 1, 2**16 - 1))
|
||||||
def test_signedness(self, mode: str, expected_color: int) -> None:
|
def test_signedness(self, mode: str, expected_color: int) -> None:
|
||||||
# see https://github.com/python-pillow/Pillow/issues/452
|
# See https://github.com/python-pillow/Pillow/issues/452
|
||||||
# pixelaccess is using signed int* instead of uint*
|
# pixelaccess is using signed int* instead of uint*
|
||||||
self.check(mode, expected_color)
|
self.check(mode, expected_color)
|
||||||
|
|
||||||
|
@ -276,13 +276,6 @@ class TestCffi(AccessTest):
|
||||||
im = Image.new(mode, (10, 10), 40000)
|
im = Image.new(mode, (10, 10), 40000)
|
||||||
self._test_get_access(im)
|
self._test_get_access(im)
|
||||||
|
|
||||||
# These don't actually appear to be modes that I can actually make,
|
|
||||||
# as unpack sets them directly into the I mode.
|
|
||||||
# im = Image.new('I;32L', (10, 10), -2**10)
|
|
||||||
# self._test_get_access(im)
|
|
||||||
# im = Image.new('I;32B', (10, 10), 2**10)
|
|
||||||
# self._test_get_access(im)
|
|
||||||
|
|
||||||
def _test_set_access(self, im: Image.Image, color: tuple[int, ...] | float) -> None:
|
def _test_set_access(self, im: Image.Image, color: tuple[int, ...] | float) -> None:
|
||||||
"""Are we writing the correct bits into the image?
|
"""Are we writing the correct bits into the image?
|
||||||
|
|
||||||
|
@ -314,23 +307,18 @@ class TestCffi(AccessTest):
|
||||||
self._test_set_access(hopper("LA"), (128, 128))
|
self._test_set_access(hopper("LA"), (128, 128))
|
||||||
self._test_set_access(hopper("1"), 255)
|
self._test_set_access(hopper("1"), 255)
|
||||||
self._test_set_access(hopper("P"), 128)
|
self._test_set_access(hopper("P"), 128)
|
||||||
# self._test_set_access(i, (128, 128)) #PA -- undone how to make
|
self._test_set_access(hopper("PA"), (128, 128))
|
||||||
self._test_set_access(hopper("F"), 1024.0)
|
self._test_set_access(hopper("F"), 1024.0)
|
||||||
|
|
||||||
for mode in ("I;16", "I;16L", "I;16B", "I;16N", "I"):
|
for mode in ("I;16", "I;16L", "I;16B", "I;16N", "I"):
|
||||||
im = Image.new(mode, (10, 10), 40000)
|
im = Image.new(mode, (10, 10), 40000)
|
||||||
self._test_set_access(im, 45000)
|
self._test_set_access(im, 45000)
|
||||||
|
|
||||||
# im = Image.new('I;32L', (10, 10), -(2**10))
|
|
||||||
# self._test_set_access(im, -(2**13)+1)
|
|
||||||
# im = Image.new('I;32B', (10, 10), 2**10)
|
|
||||||
# self._test_set_access(im, 2**13-1)
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
|
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
|
||||||
def test_not_implemented(self) -> None:
|
def test_not_implemented(self) -> None:
|
||||||
assert PyAccess.new(hopper("BGR;15")) is None
|
assert PyAccess.new(hopper("BGR;15")) is None
|
||||||
|
|
||||||
# ref https://github.com/python-pillow/Pillow/pull/2009
|
# Ref https://github.com/python-pillow/Pillow/pull/2009
|
||||||
def test_reference_counting(self) -> None:
|
def test_reference_counting(self) -> None:
|
||||||
size = 10
|
size = 10
|
||||||
|
|
||||||
|
@ -339,7 +327,7 @@ class TestCffi(AccessTest):
|
||||||
with pytest.warns(DeprecationWarning):
|
with pytest.warns(DeprecationWarning):
|
||||||
px = Image.new("L", (size, 1), 0).load()
|
px = Image.new("L", (size, 1), 0).load()
|
||||||
for i in range(size):
|
for i in range(size):
|
||||||
# pixels can contain garbage if image is released
|
# Pixels can contain garbage if image is released
|
||||||
assert px[i, 0] == 0
|
assert px[i, 0] == 0
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ("P", "PA"))
|
@pytest.mark.parametrize("mode", ("P", "PA"))
|
||||||
|
@ -456,7 +444,7 @@ int main(int argc, char* argv[])
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["PATH"] = sys.prefix + ";" + env["PATH"]
|
env["PATH"] = sys.prefix + ";" + env["PATH"]
|
||||||
|
|
||||||
# do not display the Windows Error Reporting dialog
|
# Do not display the Windows Error Reporting dialog
|
||||||
getattr(ctypes, "windll").kernel32.SetErrorMode(0x0002)
|
getattr(ctypes, "windll").kernel32.SetErrorMode(0x0002)
|
||||||
|
|
||||||
process = subprocess.Popen(["embed_pil.exe"], env=env)
|
process = subprocess.Popen(["embed_pil.exe"], env=env)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user