~jconti/ubuntu/precise/emesene/fix-956422

« back to all changes in this revision

Viewing changes to pygif/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-04-14 01:33:51 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100414013351-r2icbt5gs4ai71j8
Tags: 1.6.1-0ubuntu1
* New upstream release (LP: #562646).
* Fix missing-debian-source-format lintian warning.
* Refresh 20_dont_build_own_libmimic.patch patch.
* Bump Standards-Version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
3
#   This file is part of emesene.
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
#
 
19
 
 
20
'''unit tests for pygif
 
21
requires netpbm tools (specifically "giftopnm")'''
 
22
 
 
23
import os
 
24
import unittest
 
25
 
 
26
import pygif
 
27
 
 
28
class CloneTests(unittest.TestCase):
 
29
    '''Tests that write a gif file based on an existing gif instance'''
 
30
 
 
31
    INPUT = 'vampire.gif'
 
32
    OUTPUT = 'unittest_clone.gif'
 
33
    
 
34
    def teststructure(self):
 
35
        '''structure: basic structure test, clones gif and encodes lzw'''
 
36
        gif = pygif.GifDecoder(open(self.INPUT, 'rb').read())
 
37
 
 
38
        enc = pygif.GifEncoder()
 
39
        enc.clone(gif)
 
40
 
 
41
        image = enc.new_image()
 
42
        image.codesize, image.lzwcode = enc.lzw_encode(gif.images[0].pixels)
 
43
 
 
44
        enc.write(self.OUTPUT)
 
45
        self.assert_(giftopnmtest(self.OUTPUT))
 
46
 
 
47
class RenderTests(unittest.TestCase):
 
48
    '''Tests that render gifs from scratch or user generated data'''
 
49
    
 
50
    INPUT = 'vampire.gif'
 
51
    OUTPUT = 'unittest_render.gif'
 
52
    
 
53
    def testgradient(self):
 
54
        '''gradient: outputs a 256 color greyscale gradient'''
 
55
        enc = pygif.GifEncoder()
 
56
        
 
57
        enc.header = 'GIF89a'
 
58
        enc.ls_width = 256
 
59
        enc.ls_height = 50
 
60
        
 
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
 
65
        enc.build_flags()
 
66
        
 
67
        pixels = [x for x in range(256)] * enc.ls_height
 
68
 
 
69
        image = enc.new_image()
 
70
        image.codesize, image.lzwcode = enc.lzw_encode(pixels)
 
71
 
 
72
        enc.write(self.OUTPUT)
 
73
        self.assert_(giftopnmtest(self.OUTPUT))
 
74
 
 
75
 
 
76
def giftopnmtest(path):
 
77
    '''runs giftopnm and returns True if it succeded'''
 
78
    return os.system("giftopnm " + path + " > /dev/null 2>&1") == 0
 
79
 
 
80
if __name__ == '__main__':
 
81
    unittest.main()