1
# -*- coding: utf-8 -*-
3
# This file is part of emesene.
5
# Emesene is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# Emesene is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with emesene; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
'''unit tests for pygif
21
requires netpbm tools (specifically "giftopnm")'''
28
class CloneTests(unittest.TestCase):
29
'''Tests that write a gif file based on an existing gif instance'''
32
OUTPUT = 'unittest_clone.gif'
34
def teststructure(self):
35
'''structure: basic structure test, clones gif and encodes lzw'''
36
gif = pygif.GifDecoder(open(self.INPUT, 'rb').read())
38
enc = pygif.GifEncoder()
41
image = enc.new_image()
42
image.codesize, image.lzwcode = enc.lzw_encode(gif.images[0].pixels)
44
enc.write(self.OUTPUT)
45
self.assert_(giftopnmtest(self.OUTPUT))
47
class RenderTests(unittest.TestCase):
48
'''Tests that render gifs from scratch or user generated data'''
51
OUTPUT = 'unittest_render.gif'
53
def testgradient(self):
54
'''gradient: outputs a 256 color greyscale gradient'''
55
enc = pygif.GifEncoder()
61
enc.pallete = [(x, x, x) for x in range(256)]
62
enc.global_color_table_size = len(enc.pallete)
63
enc.color_table_flag = True
64
enc.color_resolution = 7 # 256 colors
67
pixels = [x for x in range(256)] * enc.ls_height
69
image = enc.new_image()
70
image.codesize, image.lzwcode = enc.lzw_encode(pixels)
72
enc.write(self.OUTPUT)
73
self.assert_(giftopnmtest(self.OUTPUT))
76
def giftopnmtest(path):
77
'''runs giftopnm and returns True if it succeded'''
78
return os.system("giftopnm " + path + " > /dev/null 2>&1") == 0
80
if __name__ == '__main__':