2014-09-15 23:01:05 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2014-09-15 22:24:56 +04:00
|
|
|
from test_imageqt import PillowQtTestCase
|
|
|
|
|
2015-09-17 16:32:15 +03:00
|
|
|
from PIL import ImageQt, Image
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
class TestFromQImage(PillowQtTestCase, PillowTestCase):
|
|
|
|
|
2015-09-17 16:32:15 +03:00
|
|
|
files_to_test = [
|
|
|
|
hopper(),
|
|
|
|
Image.open('Tests/images/transparent.png'),
|
|
|
|
Image.open('Tests/images/7x13.png'),
|
|
|
|
]
|
2015-12-10 01:35:35 +03:00
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
def roundtrip(self, expected):
|
2015-09-16 23:59:52 +03:00
|
|
|
# PIL -> Qt
|
|
|
|
intermediate = expected.toqimage()
|
|
|
|
# Qt -> PIL
|
|
|
|
result = ImageQt.fromqimage(intermediate)
|
|
|
|
|
|
|
|
if intermediate.hasAlphaChannel():
|
|
|
|
self.assert_image_equal(result, expected.convert('RGBA'))
|
|
|
|
else:
|
|
|
|
self.assert_image_equal(result, expected.convert('RGB'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_1(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
|
|
|
self.roundtrip(im.convert('1'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_rgb(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
|
|
|
self.roundtrip(im.convert('RGB'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_rgba(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
|
|
|
self.roundtrip(im.convert('RGBA'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_l(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
|
|
|
self.roundtrip(im.convert('L'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def test_sanity_p(self):
|
2015-09-17 16:32:15 +03:00
|
|
|
for im in self.files_to_test:
|
|
|
|
self.roundtrip(im.convert('P'))
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|