1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# (C) Copyright 2005-2023 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
import logging
import unittest
# importlib.resources is new in Python 3.7, and importlib.resources.files is
# new in Python 3.9, so for Python < 3.9 we must rely on the 3rd party
# importlib_resources package.
try:
from importlib.resources import as_file, files
except ImportError:
from importlib_resources import as_file, files
from pyface.util._optional_dependencies import optional_import
Image = None
#The work-around is to restrict to pillow < 10.0 or not use Pillow at all.
#see https://github.com/enthought/pyface/issues/1255
'''
with optional_import(
"PIL",
msg="PILImage not available due to missing pillow.",
logger=logging.getLogger(__name__)):
from PIL import Image
from ..pil_image import PILImage
image_source = files("pyface.tests") / "images" / "core.png"
'''
@unittest.skipIf(Image is None, "Pillow not available")
class TestPILImage(unittest.TestCase):
def test_create_image(self):
with as_file(image_source) as image_path:
pil_image = Image.open(image_path)
image = PILImage(pil_image)
toolkit_image = image.create_image()
self.assertIsNotNone(toolkit_image)
self.assertEqual(image.image, pil_image)
def test_create_bitmap(self):
with as_file(image_source) as image_path:
pil_image = Image.open(image_path)
image = PILImage(pil_image)
bitmap = image.create_bitmap()
self.assertIsNotNone(bitmap)
def test_create_icon(self):
with as_file(image_source) as image_path:
pil_image = Image.open(image_path)
image = PILImage(pil_image)
icon = image.create_icon()
self.assertIsNotNone(icon)
|