Do not compare properties to themselves

This commit is contained in:
Andrew Murray 2021-12-26 13:27:41 +11:00
parent 9d0703a8a8
commit 73ccda9cd1
3 changed files with 16 additions and 22 deletions

View File

@ -41,7 +41,7 @@ def test_sanity():
def test_default(): def test_default():
im = hopper("P") im = hopper("P")
assert_image(im, "P", im.size) assert im.mode == "P"
converted_im = im.convert() converted_im = im.convert()
assert_image(converted_im, "RGB", im.size) assert_image(converted_im, "RGB", im.size)
converted_im = im.convert() converted_im = im.convert()

View File

@ -2,18 +2,18 @@ import pytest
from PIL import Image 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(): def test_sanity():
image = hopper() image = hopper()
converted = image.quantize() converted = image.quantize()
assert_image(converted, "P", converted.size) assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 10) assert_image_similar(converted.convert("RGB"), image, 10)
image = hopper() image = hopper()
converted = image.quantize(palette=hopper("P")) converted = image.quantize(palette=hopper("P"))
assert_image(converted, "P", converted.size) assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 60) assert_image_similar(converted.convert("RGB"), image, 60)
@ -27,7 +27,7 @@ def test_libimagequant_quantize():
pytest.skip("libimagequant support not available") pytest.skip("libimagequant support not available")
else: else:
raise raise
assert_image(converted, "P", converted.size) assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 15) assert_image_similar(converted.convert("RGB"), image, 15)
assert len(converted.getcolors()) == 100 assert len(converted.getcolors()) == 100
@ -35,7 +35,7 @@ def test_libimagequant_quantize():
def test_octree_quantize(): def test_octree_quantize():
image = hopper() image = hopper()
converted = image.quantize(100, Image.FASTOCTREE) 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_image_similar(converted.convert("RGB"), image, 20)
assert len(converted.getcolors()) == 100 assert len(converted.getcolors()) == 100
@ -52,7 +52,7 @@ def test_quantize():
with Image.open("Tests/images/caption_6_33_22.png") as image: with Image.open("Tests/images/caption_6_33_22.png") as image:
image = image.convert("RGB") image = image.convert("RGB")
converted = image.quantize() converted = image.quantize()
assert_image(converted, "P", converted.size) assert converted.mode == "P"
assert_image_similar(converted.convert("RGB"), image, 1) assert_image_similar(converted.convert("RGB"), image, 1)
@ -62,7 +62,7 @@ def test_quantize_no_dither():
palette = palette.convert("P") palette = palette.convert("P")
converted = image.quantize(dither=0, palette=palette) converted = image.quantize(dither=0, palette=palette)
assert_image(converted, "P", converted.size) assert converted.mode == "P"
assert converted.palette.palette == palette.palette.palette assert converted.palette.palette == palette.palette.palette

View File

@ -6,7 +6,7 @@ import pytest
from PIL import Image, ImageGrab 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: class TestImageGrab:
@ -14,25 +14,20 @@ class TestImageGrab:
sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS" sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS"
) )
def test_grab(self): def test_grab(self):
for im in [ ImageGrab.grab()
ImageGrab.grab(), ImageGrab.grab(include_layered_windows=True)
ImageGrab.grab(include_layered_windows=True), ImageGrab.grab(all_screens=True)
ImageGrab.grab(all_screens=True),
]:
assert_image(im, im.mode, im.size)
im = ImageGrab.grab(bbox=(10, 20, 50, 80)) im = ImageGrab.grab(bbox=(10, 20, 50, 80))
assert_image(im, im.mode, (40, 60)) assert im.size == (40, 60)
@skip_unless_feature("xcb") @skip_unless_feature("xcb")
def test_grab_x11(self): def test_grab_x11(self):
try: try:
if sys.platform not in ("win32", "darwin"): if sys.platform not in ("win32", "darwin"):
im = ImageGrab.grab() ImageGrab.grab()
assert_image(im, im.mode, im.size)
im2 = ImageGrab.grab(xdisplay="") ImageGrab.grab(xdisplay="")
assert_image(im2, im2.mode, im2.size)
except OSError as e: except OSError as e:
pytest.skip(str(e)) pytest.skip(str(e))
@ -71,8 +66,7 @@ $bmp = New-Object Drawing.Bitmap 200, 200
assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only" assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only"
return return
im = ImageGrab.grabclipboard() ImageGrab.grabclipboard()
assert_image(im, im.mode, im.size)
@pytest.mark.skipif(sys.platform != "win32", reason="Windows only") @pytest.mark.skipif(sys.platform != "win32", reason="Windows only")
def test_grabclipboard_file(self): def test_grabclipboard_file(self):