Pillow/Tests/test_imageshow.py

66 lines
1.4 KiB
Python
Raw Normal View History

2020-01-27 14:46:52 +03:00
import pytest
from PIL import Image, ImageShow
2020-01-01 15:02:27 +03:00
from .helper import hopper, is_win32, on_ci
2020-01-27 14:46:52 +03:00
def test_sanity():
dir(Image)
dir(ImageShow)
def test_register():
# Test registering a viewer that is not a class
ImageShow.register("not a class")
# Restore original state
ImageShow._viewers.pop()
2014-06-10 13:10:47 +04:00
@pytest.mark.parametrize(
2020-08-31 00:37:17 +03:00
"order",
[-1, 0],
)
def test_viewer_show(order):
2020-01-27 14:46:52 +03:00
class TestViewer(ImageShow.Viewer):
def show_image(self, image, **options):
self.methodCalled = True
return True
2017-09-01 13:36:51 +03:00
2020-01-27 14:46:52 +03:00
viewer = TestViewer()
ImageShow.register(viewer, order)
2018-11-03 05:13:04 +03:00
2020-01-27 14:46:52 +03:00
for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
viewer.methodCalled = False
with hopper(mode) as im:
2020-01-27 14:46:52 +03:00
assert ImageShow.show(im)
assert viewer.methodCalled
2017-09-01 13:36:51 +03:00
2020-01-27 14:46:52 +03:00
# Restore original state
ImageShow._viewers.pop(0)
2019-06-13 18:54:46 +03:00
2017-09-01 13:36:51 +03:00
2020-01-27 14:46:52 +03:00
@pytest.mark.skipif(
2020-08-31 00:37:17 +03:00
not on_ci() or is_win32(),
reason="Only run on CIs; hangs on Windows CIs",
2020-01-27 14:46:52 +03:00
)
def test_show():
for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
im = hopper(mode)
assert ImageShow.show(im)
2017-09-01 13:36:51 +03:00
2018-11-03 05:13:04 +03:00
2020-01-27 14:46:52 +03:00
def test_viewer():
viewer = ImageShow.Viewer()
2019-09-21 15:28:05 +03:00
2020-01-27 14:46:52 +03:00
assert viewer.get_format(None) is None
2017-03-01 12:20:18 +03:00
2020-01-27 14:46:52 +03:00
with pytest.raises(NotImplementedError):
viewer.get_command(None)
2017-03-01 12:20:18 +03:00
2020-01-27 14:46:52 +03:00
def test_viewers():
for viewer in ImageShow._viewers:
viewer.get_command("test.jpg")