use better variable names

This commit is contained in:
Yay295 2023-01-16 07:46:11 -06:00
parent 7ad50d9185
commit 1603872f24

View File

@ -132,24 +132,25 @@ class TestImageGetPixel(AccessTest):
return 1 return 1
return tuple(range(1, bands + 1)) return tuple(range(1, bands + 1))
def check(self, mode, c=None): def check(self, mode, expected_color=None):
if not c: if not expected_color:
c = self.color(mode) expected_color = self.color(mode)
# check putpixel # check putpixel
im = Image.new(mode, (1, 1), None) im = Image.new(mode, (1, 1), None)
im.putpixel((0, 0), c) im.putpixel((0, 0), expected_color)
d = im.getpixel((0, 0)) actual_color = im.getpixel((0, 0))
assert ( assert actual_color == expected_color, (
d == c f"put/getpixel roundtrip failed for mode {mode}, "
), f"put/getpixel roundtrip failed for mode {mode}, expected {c} got {d}" f"expected {expected_color} got {actual_color}"
)
# check putpixel negative index # check putpixel negative index
im.putpixel((-1, -1), c) im.putpixel((-1, -1), expected_color)
d = im.getpixel((-1, -1)) actual_color = im.getpixel((-1, -1))
assert d == c, ( assert actual_color == expected_color, (
f"put/getpixel roundtrip negative index failed for mode {mode}, " f"put/getpixel roundtrip negative index failed for mode {mode}, "
f"expected {c} got {d}" f"expected {expected_color} got {actual_color}"
) )
# Check 0 # Check 0
@ -158,29 +159,32 @@ class TestImageGetPixel(AccessTest):
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), c) 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 0 negative index
with pytest.raises(error): with pytest.raises(error):
im.putpixel((-1, -1), c) 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), c) im = Image.new(mode, (1, 1), expected_color)
d = im.getpixel((0, 0)) actual_color = im.getpixel((0, 0))
assert d == c, f"initial color failed for mode {mode}, expected {c} got {d}" assert actual_color == expected_color, (
f"initial color failed for mode {mode}, "
f"expected {expected_color} got {actual_color}"
)
# check initial color negative index # check initial color negative index
d = im.getpixel((-1, -1)) actual_color = im.getpixel((-1, -1))
assert d == c, ( 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 {c} got {d}" f"expected {expected_color} got {actual_color}"
) )
# Check 0 # Check 0
im = Image.new(mode, (0, 0), c) 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 0 negative index