Skip to content

Commit

Permalink
Merge pull request #5907 from radarhere/assert_image
Browse files Browse the repository at this point in the history
Do not compare properties to themselves
  • Loading branch information
hugovk committed Dec 26, 2021
2 parents 9d0703a + 73ccda9 commit 11c536b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Tests/test_image_convert.py
Expand Up @@ -41,7 +41,7 @@ def convert(im, mode):
def test_default():

im = hopper("P")
assert_image(im, "P", im.size)
assert im.mode == "P"
converted_im = im.convert()
assert_image(converted_im, "RGB", im.size)
converted_im = im.convert()
Expand Down
14 changes: 7 additions & 7 deletions Tests/test_image_quantize.py
Expand Up @@ -2,18 +2,18 @@

from PIL import Image

from .helper import assert_image, assert_image_similar, hopper, is_ppc64le
from .helper import assert_image_similar, hopper, is_ppc64le


def test_sanity():
image = hopper()
converted = image.quantize()
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 10)

image = hopper()
converted = image.quantize(palette=hopper("P"))
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 60)


Expand All @@ -27,15 +27,15 @@ def test_libimagequant_quantize():
pytest.skip("libimagequant support not available")
else:
raise
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 15)
assert len(converted.getcolors()) == 100


def test_octree_quantize():
image = hopper()
converted = image.quantize(100, Image.FASTOCTREE)
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 20)
assert len(converted.getcolors()) == 100

Expand All @@ -52,7 +52,7 @@ def test_quantize():
with Image.open("Tests/images/caption_6_33_22.png") as image:
image = image.convert("RGB")
converted = image.quantize()
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 1)


Expand All @@ -62,7 +62,7 @@ def test_quantize_no_dither():
palette = palette.convert("P")

converted = image.quantize(dither=0, palette=palette)
assert_image(converted, "P", converted.size)
assert converted.mode == "P"
assert converted.palette.palette == palette.palette.palette


Expand Down
22 changes: 8 additions & 14 deletions Tests/test_imagegrab.py
Expand Up @@ -6,33 +6,28 @@

from PIL import Image, ImageGrab

from .helper import assert_image, assert_image_equal_tofile, skip_unless_feature
from .helper import assert_image_equal_tofile, skip_unless_feature


class TestImageGrab:
@pytest.mark.skipif(
sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS"
)
def test_grab(self):
for im in [
ImageGrab.grab(),
ImageGrab.grab(include_layered_windows=True),
ImageGrab.grab(all_screens=True),
]:
assert_image(im, im.mode, im.size)
ImageGrab.grab()
ImageGrab.grab(include_layered_windows=True)
ImageGrab.grab(all_screens=True)

im = ImageGrab.grab(bbox=(10, 20, 50, 80))
assert_image(im, im.mode, (40, 60))
assert im.size == (40, 60)

@skip_unless_feature("xcb")
def test_grab_x11(self):
try:
if sys.platform not in ("win32", "darwin"):
im = ImageGrab.grab()
assert_image(im, im.mode, im.size)
ImageGrab.grab()

im2 = ImageGrab.grab(xdisplay="")
assert_image(im2, im2.mode, im2.size)
ImageGrab.grab(xdisplay="")
except OSError as e:
pytest.skip(str(e))

Expand Down Expand Up @@ -71,8 +66,7 @@ def test_grabclipboard(self):
assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only"
return

im = ImageGrab.grabclipboard()
assert_image(im, im.mode, im.size)
ImageGrab.grabclipboard()

@pytest.mark.skipif(sys.platform != "win32", reason="Windows only")
def test_grabclipboard_file(self):
Expand Down

0 comments on commit 11c536b

Please sign in to comment.