Merged BGRa test into Tests/test_lib_pack.py

This commit is contained in:
Arjen Nienhuis 2016-08-08 00:07:08 +02:00
parent 916ea94052
commit 28ede3a327
2 changed files with 5 additions and 26 deletions

View File

@ -10,11 +10,11 @@ class TestLibPack(PillowTestCase):
def test_pack(self): def test_pack(self):
def pack(mode, rawmode): def pack(mode, rawmode, in_data=(1, 2, 3, 4)):
if len(mode) == 1: if len(mode) == 1:
im = Image.new(mode, (1, 1), 1) im = Image.new(mode, (1, 1), in_data[0])
else: else:
im = Image.new(mode, (1, 1), (1, 2, 3, 4)[:len(mode)]) im = Image.new(mode, (1, 1), in_data[:len(mode)])
if py3: if py3:
return list(im.tobytes("raw", rawmode)) return list(im.tobytes("raw", rawmode))
@ -47,6 +47,8 @@ class TestLibPack(PillowTestCase):
self.assertEqual(pack("RGBX", "RGBX"), [1, 2, 3, 4]) # 4->255? self.assertEqual(pack("RGBX", "RGBX"), [1, 2, 3, 4]) # 4->255?
self.assertEqual(pack("RGBA", "RGBA"), [1, 2, 3, 4]) self.assertEqual(pack("RGBA", "RGBA"), [1, 2, 3, 4])
self.assertEqual(pack("RGBA", "BGRa"), [0, 0, 0, 4])
self.assertEqual(pack("RGBA", "BGRa", in_data=(20, 30, 40, 50)), [8, 6, 4, 50])
self.assertEqual(pack("RGBa", "RGBa"), [1, 2, 3, 4]) self.assertEqual(pack("RGBa", "RGBa"), [1, 2, 3, 4])
self.assertEqual(pack("RGBa", "BGRa"), [3, 2, 1, 4]) self.assertEqual(pack("RGBa", "BGRa"), [3, 2, 1, 4])

View File

@ -1,23 +0,0 @@
from helper import unittest, PillowTestCase
from PIL import Image
class TestBGRa(PillowTestCase):
def test_bgra(self):
RGBA_RED_50 = b'\xff\x00\x00\x80' # 50% red RGBA
BGRa_RED_50 = b'\x00\x00\x80\x80' # 50% red BGRa
RGBa_RED_50 = b'\x80\x00\x00\x80' # 50% red RGBa
im = Image.frombuffer("RGBA", (1, 1), BGRa_RED_50, "raw", "BGRa", 4, 1)
self.assertEqual(im.tobytes(), RGBA_RED_50)
self.assertEqual(im.tobytes('raw', 'BGRa'), BGRa_RED_50)
im = Image.frombuffer("RGBa", (1, 1), BGRa_RED_50, "raw", "BGRa", 4, 1)
self.assertEqual(im.tobytes(), RGBa_RED_50)
self.assertEqual(im.tobytes('raw', 'BGRa'), BGRa_RED_50)
if __name__ == '__main__':
unittest.main()