Pillow/Tests/test_imageshow.py

56 lines
1.6 KiB
Python
Raw Normal View History

from PIL import Image, ImageShow
2019-09-25 12:46:54 +03:00
from .helper import PillowTestCase, hopper, is_win32, on_ci, on_github_actions, unittest
2014-06-10 13:10:47 +04:00
class TestImageShow(PillowTestCase):
def test_sanity(self):
dir(Image)
dir(ImageShow)
2017-09-01 13:36:51 +03:00
def test_register(self):
# Test registering a viewer that is not a class
ImageShow.register("not a class")
2018-11-03 05:13:04 +03:00
# Restore original state
ImageShow._viewers.pop()
2019-09-21 15:28:05 +03:00
def test_viewer_show(self):
2019-05-26 00:52:32 +03:00
class TestViewer(ImageShow.Viewer):
2017-09-01 13:36:51 +03:00
methodCalled = False
2019-05-26 00:52:32 +03:00
def show_image(self, image, **options):
2017-09-01 13:36:51 +03:00
self.methodCalled = True
return True
2019-06-13 18:54:46 +03:00
2017-09-01 13:36:51 +03:00
viewer = TestViewer()
ImageShow.register(viewer, -1)
2019-05-26 00:52:32 +03:00
for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
im = hopper(mode)
self.assertTrue(ImageShow.show(im))
self.assertTrue(viewer.methodCalled)
2017-09-01 13:36:51 +03:00
2018-11-03 05:13:04 +03:00
# Restore original state
ImageShow._viewers.pop(0)
@unittest.skipUnless(
2019-09-25 12:46:54 +03:00
on_ci() and not (is_win32() and on_github_actions()),
2019-09-25 12:28:52 +03:00
"Only run on CIs; hangs on Windows on GitHub Actions",
)
2019-09-21 15:28:05 +03:00
def test_show(self):
for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
im = hopper(mode)
self.assertTrue(ImageShow.show(im))
2017-03-01 12:20:18 +03:00
def test_viewer(self):
viewer = ImageShow.Viewer()
self.assertIsNone(viewer.get_format(None))
2017-09-01 14:05:40 +03:00
self.assertRaises(NotImplementedError, viewer.get_command, None)
2017-03-01 12:20:18 +03:00
2018-11-03 05:13:04 +03:00
def test_viewers(self):
for viewer in ImageShow._viewers:
2019-06-13 18:54:46 +03:00
viewer.get_command("test.jpg")