diff --git a/.travis.yml b/.travis.yml index 34f37b611..20d1ef5bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,22 +9,21 @@ notifications: matrix: fast_finish: true - allow_failures: - - python: nightly include: - python: "pypy" - python: "pypy3" - python: '3.6' - python: '2.7' - env: DOCKER="alpine" + - env: DOCKER="arch" # contains PyQt5 - env: DOCKER="ubuntu-trusty-x86" - env: DOCKER="ubuntu-xenial-amd64" - - env: DOCKER="ubuntu-precise-amd64" + - env: DOCKER="ubuntu-precise-amd64" + - env: DOCKER="debian-stretch-x86" - python: "2.7_with_system_site_packages" # For PyQt4 - python: '3.5' - python: '3.4' - python: '3.3' - - python: 'nightly' dist: trusty diff --git a/Tests/helper.py b/Tests/helper.py index f8eed3e2d..d5b2d97ba 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -253,6 +253,12 @@ if sys.platform == 'win32': else: IMCONVERT = 'convert' +def distro(): + if os.path.exists('/etc/os-release'): + with open('/etc/os-release', 'r') as f: + for line in f: + if 'ID=' in line: + return line.strip().split('=')[1] class cached_property(object): def __init__(self, func): diff --git a/Tests/test_image_fromqpixmap.py b/Tests/test_image_fromqpixmap.py index 543b74bbf..cf76cffca 100644 --- a/Tests/test_image_fromqpixmap.py +++ b/Tests/test_image_fromqpixmap.py @@ -1,9 +1,10 @@ -from helper import unittest, PillowTestCase, hopper +from helper import unittest, PillowTestCase, hopper, distro from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase from PIL import ImageQt - +@unittest.skipIf(ImageQt.qt_version == '5' and distro() == 'arch', + "Topixmap fails on Arch + QT5") class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase): def roundtrip(self, expected): diff --git a/Tests/test_image_toqimage.py b/Tests/test_image_toqimage.py index 4a318c5c4..5afb9a9f4 100644 --- a/Tests/test_image_toqimage.py +++ b/Tests/test_image_toqimage.py @@ -1,7 +1,7 @@ from helper import unittest, PillowTestCase, hopper from test_imageqt import PillowQtTestCase -from PIL import ImageQt +from PIL import ImageQt, Image if ImageQt.qt_is_installed: @@ -9,39 +9,66 @@ if ImageQt.qt_is_installed: try: from PyQt5 import QtGui + from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QApplication + QT_VERSION = 5 except (ImportError, RuntimeError): try: from PyQt4 import QtGui + from PyQt4.QtGui import QWidget, QHBoxLayout, QLabel, QApplication + QT_VERSION = 4 except (ImportError, RuntimeError): from PySide import QtGui + from PySide.QtGui import QWidget, QHBoxLayout, QLabel, QApplication + QT_VERSION = 4 - - class TestToQImage(PillowQtTestCase, PillowTestCase): def test_sanity(self): PillowQtTestCase.setUp(self) - for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): - data = ImageQt.toqimage(hopper(mode)) + for mode in ('RGB', 'RGBA', 'L', 'P', '1'): + src = hopper(mode) + data = ImageQt.toqimage(src) self.assertIsInstance(data, QImage) self.assertFalse(data.isNull()) + # reload directly from the qimage + rt = ImageQt.fromqimage(data) + if mode in ('L', 'P', '1'): + self.assert_image_equal(rt, src.convert('RGB')) + else: + self.assert_image_equal(rt, src) + + if mode == '1': + # BW appears to not save correctly on QT4 and QT5 + # kicks out errors on console: + # libpng warning: Invalid color type/bit depth combination in IHDR + # libpng error: Invalid IHDR data + continue + # Test saving the file tempfile = self.tempfile('temp_{}.png'.format(mode)) data.save(tempfile) + # Check that it actually worked. + reloaded = Image.open(tempfile) + # Gray images appear to come back in palette mode. + # They're roughly equivalent + if QT_VERSION == 4 and mode == 'L': + src = src.convert('P') + self.assert_image_equal(reloaded, src) + def test_segfault(self): PillowQtTestCase.setUp(self) - app = QtGui.QApplication([]) + app = QApplication([]) ex = Example() if ImageQt.qt_is_installed: - class Example(QtGui.QWidget): + class Example(QWidget): def __init__(self): super(Example, self).__init__() @@ -52,9 +79,9 @@ if ImageQt.qt_is_installed: pixmap1 = QtGui.QPixmap.fromImage(qimage) - hbox = QtGui.QHBoxLayout(self) + hbox = QHBoxLayout(self) - lbl = QtGui.QLabel(self) + lbl = QLabel(self) # Segfault in the problem lbl.setPixmap(pixmap1.copy()) @@ -62,7 +89,7 @@ if ImageQt.qt_is_installed: def main(): - app = QtGui.QApplication(sys.argv) + app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_()) diff --git a/Tests/test_image_toqpixmap.py b/Tests/test_image_toqpixmap.py index c6555d7ff..a48e278ad 100644 --- a/Tests/test_image_toqpixmap.py +++ b/Tests/test_image_toqpixmap.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, hopper +from helper import unittest, PillowTestCase, hopper, distro from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase from PIL import ImageQt @@ -9,6 +9,8 @@ if ImageQt.qt_is_installed: class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase): + @unittest.skipIf(ImageQt.qt_version == '5' and distro() == 'arch', + "Topixmap fails on Arch + QT5") def test_sanity(self): PillowQtTestCase.setUp(self)