2020-01-27 14:46:52 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
from PIL import Image, ImageShow
|
2012-10-16 00:26:38 +04:00
|
|
|
|
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()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2020-06-18 14:40:38 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"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()
|
2020-06-18 14:40:38 +03:00
|
|
|
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"):
|
2020-06-18 14:40:38 +03:00
|
|
|
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-03-28 00:22:51 +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")
|