From 9ff5cab8b1fce5bf860ac9780402adedea0e8b44 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 29 Dec 2016 11:28:58 +1100 Subject: [PATCH] Added test --- Tests/test_file_gif.py | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index 94a8ea92c..75aafbc72 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -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()