This commit is contained in:
dutcu 2024-06-13 23:50:07 +02:00
parent 7db3563c91
commit 666d41d3ea
2 changed files with 6 additions and 49 deletions

View File

@ -94,16 +94,15 @@ def test_ipythonviewer() -> None:
im = hopper()
assert test_viewer.show(im) == 1
def test_viewer_exceptions() -> None:
viewer = ImageShow.Viewer()
class TestViewerException(ImageShow.Viewer):
pass
viewer = TestViewerException()
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:
@ -113,12 +112,9 @@ def test_viewer_show_edge_cases() -> None:
viewer = TestViewer()
ImageShow.register(viewer)
for mode in ["", "special characters", "a" * 1000]:
for mode in ["1", "L", "RGB"]:
viewer.methodCalled = False
with hopper(mode) as im:
assert ImageShow.show(im)
assert viewer.methodCalled
# Restore original state
ImageShow._viewers.pop(0)

View File

@ -1,39 +0,0 @@
from __future__ import annotations
import locale
import pytest
from PIL import Image
# ref https://github.com/python-pillow/Pillow/issues/272
# on windows, in polish locale:
# import locale
# print(locale.setlocale(locale.LC_ALL, 'polish'))
# import string
# print(len(string.whitespace))
# print(ord(string.whitespace[6]))
# Polish_Poland.1250
# 7
# 160
# one of string.whitespace is not freely convertible into ascii.
path = "Tests/images/hopper.jpg"
def test_sanity() -> None:
with Image.open(path):
pass
try:
locale.setlocale(locale.LC_ALL, "polish")
except locale.Error:
pytest.skip("Polish locale not available")
try:
with Image.open(path):
pass
finally:
locale.setlocale(locale.LC_ALL, (None, None))