From 29fb4523d5301fd1d1b2d5f5fc8e839d3404790f Mon Sep 17 00:00:00 2001 From: wiredfool Date: Wed, 20 Nov 2013 22:19:28 -0800 Subject: [PATCH] tests for imageqt4/5 --- Tests/test_imageqt.py | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 8d6ac9f3c..36e673a90 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -1,9 +1,39 @@ from tester import * from PIL import Image -try: - from PIL import ImageQt -except ImportError as v: - skip(v) -success() +try: + from PyQt5.QtGui import QImage, qRgb, qRgba +except: + try: + from PyQt4.QtGui import QImage, qRgb, qRgba + except: + skip('PyQT4 or 5 not installed') + +from PIL import ImageQt + +def test_rgb(): + # from https://qt-project.org/doc/qt-4.8/qcolor.html + # typedef QRgb + # An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int. + + assert_equal(qRgb(0,0,0), qRgba(0,0,0,255)) + + def checkrgb(r,g,b): + val = ImageQt.rgb(r,g,b) + print val + val = val % 2**24 # drop the alpha + assert_equal(val >> 16, r) + assert_equal(((val >> 8 ) % 2**8), g) + assert_equal(val % 2**8, b) + + checkrgb(0,0,0) + checkrgb(255,0,0) + checkrgb(0,255,0) + checkrgb(0,0,255) + + +def test_image(): + for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): + print ( "Testing mode %s" % mode) + assert_no_exception(lambda: ImageQt.ImageQt(lena(mode)))