Pillow/Tests/test_imageqt.py

60 lines
1.6 KiB
Python
Raw Normal View History

from helper import unittest, PillowTestCase, hopper
2013-11-21 10:19:28 +04:00
try:
2014-06-10 13:10:47 +04:00
from PIL import ImageQt
2013-11-21 10:19:28 +04:00
from PyQt5.QtGui import QImage, qRgb, qRgba
except:
try:
from PyQt4.QtGui import QImage, qRgb, qRgba
except:
try:
from PySide.QtGui import QImage, qRgb, qRgba
except:
# Will be skipped in setUp
pass
2014-06-10 13:10:47 +04:00
class TestImageQt(PillowTestCase):
def setUp(self):
try:
from PyQt5.QtGui import QImage, qRgb, qRgba
2015-05-27 02:15:45 +03:00
except ImportError:
2014-06-10 13:10:47 +04:00
try:
from PyQt4.QtGui import QImage, qRgb, qRgba
2015-05-27 02:15:45 +03:00
except ImportError:
try:
from PySide.QtGui import QImage, qRgb, qRgba
2015-05-27 02:15:45 +03:00
except ImportError:
self.skipTest('PyQt4 or 5 or PySide not installed')
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.
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)
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()
# End of file