From f58f690835b7ee76cc85527ba875920cda000a81 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 4 Aug 2018 20:18:36 +1000 Subject: [PATCH 1/2] Removed unnecessary setUp calls --- Tests/test_image_fromqpixmap.py | 3 +-- Tests/test_image_toqimage.py | 3 --- Tests/test_image_toqpixmap.py | 4 +--- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Tests/test_image_fromqpixmap.py b/Tests/test_image_fromqpixmap.py index 543b74bbf..0127f77e2 100644 --- a/Tests/test_image_fromqpixmap.py +++ b/Tests/test_image_fromqpixmap.py @@ -1,5 +1,5 @@ from helper import unittest, PillowTestCase, hopper -from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase +from test_imageqt import PillowQPixmapTestCase from PIL import ImageQt @@ -7,7 +7,6 @@ from PIL import ImageQt class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase): def roundtrip(self, expected): - PillowQtTestCase.setUp(self) result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected)) # Qt saves all pixmaps as rgb self.assert_image_equal(result, expected.convert('RGB')) diff --git a/Tests/test_image_toqimage.py b/Tests/test_image_toqimage.py index c9971cf73..896cf13fb 100644 --- a/Tests/test_image_toqimage.py +++ b/Tests/test_image_toqimage.py @@ -25,7 +25,6 @@ if ImageQt.qt_is_installed: class TestToQImage(PillowQtTestCase, PillowTestCase): def test_sanity(self): - PillowQtTestCase.setUp(self) for mode in ('RGB', 'RGBA', 'L', 'P', '1'): src = hopper(mode) data = ImageQt.toqimage(src) @@ -61,8 +60,6 @@ class TestToQImage(PillowQtTestCase, PillowTestCase): self.assert_image_equal(reloaded, src) def test_segfault(self): - PillowQtTestCase.setUp(self) - app = QApplication([]) ex = Example() assert(app) # Silence warning diff --git a/Tests/test_image_toqpixmap.py b/Tests/test_image_toqpixmap.py index c6555d7ff..5de7810f5 100644 --- a/Tests/test_image_toqpixmap.py +++ b/Tests/test_image_toqpixmap.py @@ -1,5 +1,5 @@ from helper import unittest, PillowTestCase, hopper -from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase +from test_imageqt import PillowQPixmapTestCase from PIL import ImageQt @@ -10,8 +10,6 @@ if ImageQt.qt_is_installed: class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase): def test_sanity(self): - PillowQtTestCase.setUp(self) - for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): data = ImageQt.toqpixmap(hopper(mode)) From dad0fd6d3893f6f27b9042d5de3aa97704d9456e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 4 Aug 2018 23:21:43 +1000 Subject: [PATCH 2/2] Moved QApplication and QGuiApplication testing into separate threads --- Tests/test_image_fromqpixmap.py | 8 +++++--- Tests/test_image_toqimage.py | 10 ++++++---- Tests/test_image_toqpixmap.py | 16 +++++++++------- Tests/test_imageqt.py | 22 ++++++++++++++++------ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Tests/test_image_fromqpixmap.py b/Tests/test_image_fromqpixmap.py index 0127f77e2..d03f2d0e4 100644 --- a/Tests/test_image_fromqpixmap.py +++ b/Tests/test_image_fromqpixmap.py @@ -7,9 +7,11 @@ from PIL import ImageQt class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase): def roundtrip(self, expected): - result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected)) - # Qt saves all pixmaps as rgb - self.assert_image_equal(result, expected.convert('RGB')) + def test(): + result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected)) + # Qt saves all pixmaps as rgb + self.assert_image_equal(result, expected.convert('RGB')) + self.executeInSeparateProcess(test) def test_sanity_1(self): self.roundtrip(hopper('1')) diff --git a/Tests/test_image_toqimage.py b/Tests/test_image_toqimage.py index 896cf13fb..bb238c622 100644 --- a/Tests/test_image_toqimage.py +++ b/Tests/test_image_toqimage.py @@ -60,10 +60,12 @@ class TestToQImage(PillowQtTestCase, PillowTestCase): self.assert_image_equal(reloaded, src) def test_segfault(self): - app = QApplication([]) - ex = Example() - assert(app) # Silence warning - assert(ex) # Silence warning + def test(): + app = QApplication([]) + ex = Example() + assert(app) # Silence warning + assert(ex) # Silence warning + self.executeInSeparateProcess(test) if ImageQt.qt_is_installed: diff --git a/Tests/test_image_toqpixmap.py b/Tests/test_image_toqpixmap.py index 5de7810f5..d3975cb67 100644 --- a/Tests/test_image_toqpixmap.py +++ b/Tests/test_image_toqpixmap.py @@ -10,15 +10,17 @@ if ImageQt.qt_is_installed: class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase): def test_sanity(self): - for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): - data = ImageQt.toqpixmap(hopper(mode)) + def test(): + for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): + data = ImageQt.toqpixmap(hopper(mode)) - self.assertIsInstance(data, QPixmap) - self.assertFalse(data.isNull()) + self.assertIsInstance(data, QPixmap) + self.assertFalse(data.isNull()) - # Test saving the file - tempfile = self.tempfile('temp_{}.png'.format(mode)) - data.save(tempfile) + # Test saving the file + tempfile = self.tempfile('temp_{}.png'.format(mode)) + data.save(tempfile) + self.executeInSeparateProcess(test) if __name__ == '__main__': diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index cf9712ace..04bfef203 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -2,6 +2,7 @@ from helper import unittest, PillowTestCase, hopper from PIL import ImageQt +import multiprocessing if ImageQt.qt_is_installed: from PIL.ImageQt import qRgba @@ -18,6 +19,21 @@ class PillowQtTestCase(object): def setUp(self): skip_if_qt_is_not_installed(self) + def executeInSeparateProcess(self, test): + def target(): + if ImageQt.qt_version == '5': + from PyQt5.QtGui import QGuiApplication + elif ImageQt.qt_version == '4': + from PyQt4.QtGui import QGuiApplication + elif ImageQt.qt_version == 'side': + from PySide.QtGui import QGuiApplication + app = QGuiApplication([]) + test() + app.quit() + p = multiprocessing.Process(target=target) + p.start() + p.join() + def tearDown(self): pass @@ -36,12 +52,6 @@ class PillowQPixmapTestCase(PillowQtTestCase): except ImportError: self.skipTest('QGuiApplication not installed') - self.app = QGuiApplication([]) - - def tearDown(self): - PillowQtTestCase.tearDown(self) - self.app.quit() - class TestImageQt(PillowQtTestCase, PillowTestCase):