Pillow/Tests/test_imageqt.py

85 lines
2.3 KiB
Python
Raw Normal View History

from .helper import unittest, PillowTestCase, hopper
2013-11-21 10:19:28 +04:00
from PIL import ImageQt
if ImageQt.qt_is_installed:
2015-06-19 08:35:56 +03:00
from PIL.ImageQt import qRgba
def skip_if_qt_is_not_installed(_):
pass
else:
def skip_if_qt_is_not_installed(test_case):
2015-06-19 11:23:17 +03:00
test_case.skipTest('Qt bindings are not installed')
2014-06-10 13:10:47 +04:00
2015-06-19 08:36:23 +03:00
class PillowQtTestCase(object):
2014-06-10 13:10:47 +04:00
def setUp(self):
skip_if_qt_is_not_installed(self)
def tearDown(self):
pass
2015-06-19 08:36:23 +03:00
class PillowQPixmapTestCase(PillowQtTestCase):
def setUp(self):
PillowQtTestCase.setUp(self)
2015-06-19 08:35:56 +03:00
try:
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
2018-08-03 16:07:19 +03:00
elif ImageQt.qt_version == 'side2':
from PySide2.QtGui import QGuiApplication
2015-06-19 08:35:56 +03:00
except ImportError:
self.skipTest('QGuiApplication not installed')
2015-06-19 08:36:23 +03:00
self.app = QGuiApplication([])
def tearDown(self):
PillowQtTestCase.tearDown(self)
self.app.quit()
class TestImageQt(PillowQtTestCase, PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_rgb(self):
2018-06-23 03:58:41 +03:00
# from https://doc.qt.io/archives/qt-4.8/qcolor.html
2014-06-10 13:10:47 +04:00
# typedef QRgb
# An ARGB quadruplet on the format #AARRGGBB,
# equivalent to an unsigned int.
2015-06-19 08:35:56 +03:00
if ImageQt.qt_version == '5':
from PyQt5.QtGui import qRgb
elif ImageQt.qt_version == '4':
from PyQt4.QtGui import qRgb
elif ImageQt.qt_version == 'side':
from PySide.QtGui import qRgb
2018-08-03 16:07:19 +03:00
elif ImageQt.qt_version == 'side2':
from PySide2.QtGui import qRgb
2014-06-10 13:10:47 +04:00
self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255))
def checkrgb(r, g, b):
val = ImageQt.rgb(r, g, b)
val = val % 2**24 # drop the alpha
self.assertEqual(val >> 16, r)
self.assertEqual(((val >> 8) % 2**8), g)
self.assertEqual(val % 2**8, b)
checkrgb(0, 0, 0)
checkrgb(255, 0, 0)
checkrgb(0, 255, 0)
checkrgb(0, 0, 255)
2015-06-19 11:23:17 +03:00
def test_image(self):
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
ImageQt.ImageQt(hopper(mode))
2014-06-10 13:10:47 +04:00
if __name__ == '__main__':
unittest.main()