Added test

This commit is contained in:
Andrew Murray 2016-12-29 11:28:58 +11:00
parent 7c0631b4c6
commit 9ff5cab8b1

View File

@ -56,7 +56,7 @@ class TestFileGif(PillowTestCase):
# 256 color Palette image, posterize to > 128 and < 128 levels
# Size bigger and smaller than 512x512
# Check the palette for number of colors allocated.
# Check for correctness after conversion back to RGB
# Check for correctness after conversion back to RGB
def check(colors, size, expected_palette_length):
# make an image with empty colors in the start of the palette range
im = Image.frombytes('P', (colors,colors),
@ -70,7 +70,7 @@ class TestFileGif(PillowTestCase):
# check palette length
palette_length = max(i+1 for i,v in enumerate(reloaded.histogram()) if v)
self.assertEqual(expected_palette_length, palette_length)
self.assert_image_equal(im.convert('RGB'), reloaded.convert('RGB'))
@ -288,7 +288,7 @@ class TestFileGif(PillowTestCase):
im_list = [
Image.new('L', (100, 100), '#000'),
Image.new('L', (100, 100), '#111'),
Image.new('L', (100, 100), '#222'),
Image.new('L', (100, 100), '#222')
]
#duration as list
@ -323,7 +323,31 @@ class TestFileGif(PillowTestCase):
except EOFError:
pass
def test_identical_frames(self):
duration_list = [1000, 1500, 2000, 4000]
out = self.tempfile('temp.gif')
im_list = [
Image.new('L', (100, 100), '#000'),
Image.new('L', (100, 100), '#000'),
Image.new('L', (100, 100), '#000'),
Image.new('L', (100, 100), '#111')
]
#duration as list
im_list[0].save(
out,
save_all=True,
append_images=im_list[1:],
duration=duration_list
)
reread = Image.open(out)
# Assert that the first three frames were combined
self.assertEqual(reread.n_frames, 2)
# Assert that the new duration is the total of the identical frames
self.assertEqual(reread.info['duration'], 4500)
def test_number_of_loops(self):
number_of_loops = 2
@ -427,7 +451,7 @@ class TestFileGif(PillowTestCase):
reloaded = Image.open(out)
self.assertEqual(reloaded.info['transparency'], 253)
if __name__ == '__main__':
unittest.main()