mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-04 20:40:11 +03:00
tests
This commit is contained in:
parent
0a45381c2b
commit
7db3563c91
|
@ -41,6 +41,8 @@ def test_is_animated() -> None:
|
|||
def test_tell() -> None:
|
||||
with Image.open(TEST_FILE) as im:
|
||||
assert im.tell() == 0
|
||||
im.seek(1)
|
||||
assert im.tell() == 1
|
||||
|
||||
|
||||
def test_seek() -> None:
|
||||
|
|
|
@ -95,6 +95,10 @@ def test_fromarray_strides_without_tobytes() -> None:
|
|||
class Wrapper:
|
||||
def __init__(self, arr_params: dict[str, Any]) -> None:
|
||||
self.__array_interface__ = arr_params
|
||||
self.data = numpy.zeros(arr_params['shape'], dtype=numpy.uint8).tobytes()
|
||||
|
||||
def tostring(self):
|
||||
return self.data
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
wrapped = Wrapper({"shape": (1, 1), "strides": (1, 1)})
|
||||
|
|
|
@ -94,3 +94,31 @@ def test_ipythonviewer() -> None:
|
|||
|
||||
im = hopper()
|
||||
assert test_viewer.show(im) == 1
|
||||
|
||||
def test_viewer_exceptions() -> None:
|
||||
viewer = ImageShow.Viewer()
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
viewer.show_image(Image.new("L", (1, 1)))
|
||||
|
||||
with pytest.raises(NotImplementedError):
|
||||
viewer.save_image(Image.new("L", (1, 1)))
|
||||
|
||||
def test_viewer_show_edge_cases() -> None:
|
||||
class TestViewer(ImageShow.Viewer):
|
||||
def show_image(self, image: Image.Image, **options: Any) -> bool:
|
||||
self.methodCalled = True
|
||||
return True
|
||||
|
||||
viewer = TestViewer()
|
||||
ImageShow.register(viewer)
|
||||
|
||||
for mode in ["", "special characters", "a" * 1000]:
|
||||
viewer.methodCalled = False
|
||||
with hopper(mode) as im:
|
||||
assert ImageShow.show(im)
|
||||
assert viewer.methodCalled
|
||||
|
||||
# Restore original state
|
||||
ImageShow._viewers.pop(0)
|
||||
|
|
@ -1,15 +1,46 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from .helper import assert_image_equal, assert_image_similar, hopper
|
||||
|
||||
@pytest.fixture
|
||||
def result():
|
||||
return hopper("P").convert("RGB")
|
||||
|
||||
def check_upload_equal() -> None:
|
||||
result = hopper("P").convert("RGB")
|
||||
target = hopper("RGB")
|
||||
@pytest.fixture
|
||||
def target():
|
||||
return hopper("RGB")
|
||||
|
||||
def test_upload_equal(result, target):
|
||||
assert_image_equal(result, target)
|
||||
|
||||
def test_upload_similar(result, target, epsilon):
|
||||
assert_image_similar(result, target, epsilon)
|
||||
|
||||
def check_upload_similar() -> None:
|
||||
@pytest.mark.parametrize("epsilon", [0, 1, 100])
|
||||
def test_upload_similar_parametrized(result, target, epsilon):
|
||||
assert_image_similar(result, target, epsilon)
|
||||
|
||||
def test_upload_equal_different_formats():
|
||||
result = Image.open("Tests/images/hopper_webp.png").convert("RGB")
|
||||
target = Image.open("Tests/images/hopper_webp.tif").convert("RGB")
|
||||
assert_image_equal(result, target)
|
||||
|
||||
def test_upload_equal_different_sizes():
|
||||
result = hopper("P").resize((100, 100)).convert("RGB")
|
||||
target = hopper("RGB").resize((200, 200))
|
||||
assert_image_equal(result, target)
|
||||
|
||||
def test_upload_not_similar():
|
||||
result = hopper("P").convert("RGB")
|
||||
target = hopper("RGB")
|
||||
assert_image_similar(result, target, 0)
|
||||
target = Image.new("RGB", (100, 100), "white")
|
||||
with pytest.raises(AssertionError):
|
||||
assert_image_similar(result, target, 0)
|
||||
|
||||
def test_upload_equal_different_modes():
|
||||
result = hopper("L").convert("RGB")
|
||||
target = hopper("1").convert("RGB")
|
||||
assert_image_equal(result, target)
|
||||
|
BIN
boy meets evil.png
Normal file
BIN
boy meets evil.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 MiB |
15
display_image.py
Normal file
15
display_image.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import time
|
||||
import matplotlib
|
||||
matplotlib.use('TkAgg')
|
||||
from PIL import Image
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Open an image file
|
||||
img = Image.open('boy meets evil.png')
|
||||
|
||||
# Display the image
|
||||
plt.imshow(img)
|
||||
plt.show()
|
||||
|
||||
# Keep the script running for a while
|
||||
time.sleep(10) # keeps the script running for 10 seconds
|
Loading…
Reference in New Issue
Block a user