Pillow/Tests/test_imageqt.py

78 lines
2.0 KiB
Python
Raw Normal View History

2015-06-19 08:35:56 +03:00
from helper import unittest, PillowTestCase
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):
test_case.skipTest('PyQt4, PyQt5, or PySide is not installed')
2014-06-10 13:10:47 +04:00
class PillowQtTestCase:
2014-06-10 13:10:47 +04:00
def setUp(self):
skip_if_qt_is_not_installed(self)
def tearDown(self):
pass
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
except ImportError:
self.skipTest('QGuiApplication not installed')
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):
# 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.
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
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)
if __name__ == '__main__':
unittest.main()
# End of file