enthought / pyface

pyface: traits-capable windowing framework
Other
106 stars 55 forks source link

Bug report: test failures with PyQt5 #1255

Open opoplawski opened 1 year ago

opoplawski commented 1 year ago

Environment

OS: Fedora Rawhide Python version: 3.12 Toolkit: Qt 5.15.10 Qt API: PyQt5 5.15.9

Description

======================================================================
ERROR: test_create_bitmap (pyface.tests.test_pil_image.TestPILImage.test_create_bitmap)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/tests/test_pil_image.py", line 52, in test_create_bitmap
    bitmap = image.create_bitmap()
             ^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/i_pil_image.py", line 55, in create_bitmap
    return image_to_bitmap(self.create_image(size))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/ui/qt/util/image_helpers.py", line 48, in image_to_bitmap
    bitmap = QPixmap.fromImage(image)
             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromImage(image: QImage, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.AutoColor): argument 1 has unexpected type 'ImageQt'
======================================================================
ERROR: test_create_icon (pyface.tests.test_pil_image.TestPILImage.test_create_icon)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/tests/test_pil_image.py", line 59, in test_create_icon
    icon = image.create_icon()
           ^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/i_pil_image.py", line 73, in create_icon
    return bitmap_to_icon(self.create_bitmap(size))
                          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/i_pil_image.py", line 55, in create_bitmap
    return image_to_bitmap(self.create_image(size))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILDROOT/python-pyface-8.0.0-1.fc40~bootstrap.noarch/usr/lib/python3.12/site-packages/pyface/ui/qt/util/image_helpers.py", line 48, in image_to_bitmap
    bitmap = QPixmap.fromImage(image)
             ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromImage(image: QImage, flags: Union[Qt.ImageConversionFlags, Qt.ImageConversionFlag] = Qt.AutoColor): argument 1 has unexpected type 'ImageQt'
----------------------------------------------------------------------

Steps to Reproduce

+ export QT_API=pyqt5
+ QT_API=pyqt5
+ case $toolkit in
+ export ETS_TOOLKIT=qt
+ ETS_TOOLKIT=qt
+ export EXCLUDE_TESTS=wx
+ EXCLUDE_TESTS=wx
+ xvfb-run /usr/bin/python3 -Xfaulthandler -s -m unittest discover -v pyface
corranwebster commented 1 year ago

Which version of Pillow are you using? Pillow dropped support for Qt5 in Pillow 10 so we've been seeing issues with other ETS projects when pip-installing Pillow into Qt5-based environments.

opoplawski commented 1 year ago

This is indeed with pillow 10.0.0. Is this a show stopper for pyface and Qt5 then?

corranwebster commented 1 year ago

The only work-around is to restrict to pillow < 10.0 or not use Pillow at all.

Pillow is nominally an optional dependency of Pyface for Qt backends - it should work without Pillow installed as long as the application code avoids using PILImage. I expect that if you test in an environment without Pillow installed, tests should pass (the PILImage tests will be skipped).

The end-user failure mode if pillow 10 is installed will only occur if a PILImage is created by application code. PILImage is a fairly new class, so it's probably not in a lot of downstream code.

I don't know if this helps your use-case.

opoplawski commented 1 year ago

Thank you, that's very helpful information.