mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Moved QApplication into one test
This commit is contained in:
parent
41462d8c55
commit
62693b7c54
|
@ -8,27 +8,6 @@ if ImageQt.qt_is_installed:
|
|||
from PIL.ImageQt import qRgba
|
||||
|
||||
|
||||
@pytest.mark.skipif(not ImageQt.qt_is_installed, reason="Qt bindings are not installed")
|
||||
class PillowQPixmapTestCase:
|
||||
@classmethod
|
||||
def setup_class(self):
|
||||
try:
|
||||
if ImageQt.qt_version == "5":
|
||||
from PyQt5.QtGui import QGuiApplication
|
||||
elif ImageQt.qt_version == "side2":
|
||||
from PySide2.QtGui import QGuiApplication
|
||||
except ImportError:
|
||||
pytest.skip("QGuiApplication not installed")
|
||||
return
|
||||
|
||||
self.app = QGuiApplication([])
|
||||
|
||||
@classmethod
|
||||
def teardown_class(self):
|
||||
self.app.quit()
|
||||
self.app = None
|
||||
|
||||
|
||||
@pytest.mark.skipif(not ImageQt.qt_is_installed, reason="Qt bindings are not installed")
|
||||
def test_rgb():
|
||||
# from https://doc.qt.io/archives/qt-4.8/qcolor.html
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
from PIL import ImageQt
|
||||
|
||||
from .helper import assert_image_equal, hopper
|
||||
from .test_imageqt import PillowQPixmapTestCase
|
||||
|
||||
|
||||
class TestFromQPixmap(PillowQPixmapTestCase):
|
||||
def roundtrip(self, expected):
|
||||
result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
|
||||
# Qt saves all pixmaps as rgb
|
||||
assert_image_equal(result, expected.convert("RGB"))
|
||||
|
||||
def test_sanity(self):
|
||||
for mode in ("1", "RGB", "RGBA", "L", "P"):
|
||||
self.roundtrip(hopper(mode))
|
63
Tests/test_qt_image_qapplication.py
Normal file
63
Tests/test_qt_image_qapplication.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
import pytest
|
||||
|
||||
from PIL import ImageQt
|
||||
|
||||
from .helper import assert_image_equal, hopper
|
||||
|
||||
if ImageQt.qt_is_installed:
|
||||
from PIL.ImageQt import QPixmap
|
||||
|
||||
if ImageQt.qt_version == "5":
|
||||
from PyQt5 import QtGui
|
||||
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||
elif ImageQt.qt_version == "side2":
|
||||
from PySide2 import QtGui
|
||||
from PySide2.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||
|
||||
class Example(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
img = hopper().resize((1000, 1000))
|
||||
|
||||
qimage = ImageQt.ImageQt(img)
|
||||
|
||||
pixmap1 = QtGui.QPixmap.fromImage(qimage)
|
||||
|
||||
QHBoxLayout(self) # hbox
|
||||
|
||||
lbl = QLabel(self)
|
||||
# Segfault in the problem
|
||||
lbl.setPixmap(pixmap1.copy())
|
||||
|
||||
|
||||
def roundtrip(expected):
|
||||
result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
|
||||
# Qt saves all pixmaps as rgb
|
||||
assert_image_equal(result, expected.convert("RGB"))
|
||||
|
||||
|
||||
@pytest.mark.skipif(not ImageQt.qt_is_installed, reason="Qt bindings are not installed")
|
||||
def test_sanity(tmp_path):
|
||||
# Segfault test
|
||||
app = QApplication([])
|
||||
ex = Example()
|
||||
assert app # Silence warning
|
||||
assert ex # Silence warning
|
||||
|
||||
for mode in ("1", "RGB", "RGBA", "L", "P"):
|
||||
# to QPixmap
|
||||
data = ImageQt.toqpixmap(hopper(mode))
|
||||
|
||||
assert isinstance(data, QPixmap)
|
||||
assert not data.isNull()
|
||||
|
||||
# Test saving the file
|
||||
tempfile = str(tmp_path / f"temp_{mode}.png")
|
||||
data.save(tempfile)
|
||||
|
||||
# from QPixmap
|
||||
roundtrip(hopper(mode))
|
||||
|
||||
app.quit()
|
||||
app = None
|
|
@ -11,13 +11,6 @@ pytestmark = pytest.mark.skipif(
|
|||
if ImageQt.qt_is_installed:
|
||||
from PIL.ImageQt import QImage
|
||||
|
||||
try:
|
||||
from PyQt5 import QtGui
|
||||
from PyQt5.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||
except (ImportError, RuntimeError):
|
||||
from PySide2 import QtGui
|
||||
from PySide2.QtWidgets import QApplication, QHBoxLayout, QLabel, QWidget
|
||||
|
||||
|
||||
def test_sanity(tmp_path):
|
||||
for mode in ("RGB", "RGBA", "L", "P", "1"):
|
||||
|
@ -49,29 +42,3 @@ def test_sanity(tmp_path):
|
|||
# Check that it actually worked.
|
||||
with Image.open(tempfile) as reloaded:
|
||||
assert_image_equal(reloaded, src)
|
||||
|
||||
|
||||
def test_segfault():
|
||||
app = QApplication([])
|
||||
ex = Example()
|
||||
assert app # Silence warning
|
||||
assert ex # Silence warning
|
||||
|
||||
|
||||
if ImageQt.qt_is_installed:
|
||||
|
||||
class Example(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
img = hopper().resize((1000, 1000))
|
||||
|
||||
qimage = ImageQt.ImageQt(img)
|
||||
|
||||
pixmap1 = QtGui.QPixmap.fromImage(qimage)
|
||||
|
||||
QHBoxLayout(self) # hbox
|
||||
|
||||
lbl = QLabel(self)
|
||||
# Segfault in the problem
|
||||
lbl.setPixmap(pixmap1.copy())
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
from PIL import ImageQt
|
||||
|
||||
from .helper import hopper
|
||||
from .test_imageqt import PillowQPixmapTestCase
|
||||
|
||||
if ImageQt.qt_is_installed:
|
||||
from PIL.ImageQt import QPixmap
|
||||
|
||||
|
||||
class TestToQPixmap(PillowQPixmapTestCase):
|
||||
def test_sanity(self, tmp_path):
|
||||
for mode in ("1", "RGB", "RGBA", "L", "P"):
|
||||
data = ImageQt.toqpixmap(hopper(mode))
|
||||
|
||||
assert isinstance(data, QPixmap)
|
||||
assert not data.isNull()
|
||||
|
||||
# Test saving the file
|
||||
tempfile = str(tmp_path / f"temp_{mode}.png")
|
||||
data.save(tempfile)
|
Loading…
Reference in New Issue
Block a user