2019-01-13 20:00:12 +03:00
|
|
|
from .helper import unittest, PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
from PIL import ImageShow
|
|
|
|
|
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()
|
|
|
|
|
2017-09-01 13:36:51 +03:00
|
|
|
def test_show(self):
|
|
|
|
class TestViewer:
|
|
|
|
methodCalled = False
|
|
|
|
|
|
|
|
def show(self, image, title=None, **options):
|
|
|
|
self.methodCalled = True
|
|
|
|
return True
|
|
|
|
viewer = TestViewer()
|
|
|
|
ImageShow.register(viewer, -1)
|
|
|
|
|
|
|
|
im = hopper()
|
|
|
|
self.assertTrue(ImageShow.show(im))
|
|
|
|
self.assertTrue(viewer.methodCalled)
|
|
|
|
|
2018-11-03 05:13:04 +03:00
|
|
|
# Restore original state
|
|
|
|
ImageShow._viewers.pop(0)
|
|
|
|
|
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:
|
|
|
|
viewer.get_command('test.jpg')
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|