~ubuntu-branches/ubuntu/wily/python-imaging/wily

« back to all changes in this revision

Viewing changes to Tests/test_imagepalette.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (1.1.4)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130131204920-7tnuhqhlsqdza4c2
Rewrite build dependencies to allow cross builds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from tester import *
 
2
 
 
3
from PIL import Image
 
4
from PIL import ImagePalette
 
5
 
 
6
ImagePalette = ImagePalette.ImagePalette
 
7
 
 
8
def test_sanity():
 
9
 
 
10
    assert_no_exception(lambda: ImagePalette("RGB", list(range(256))*3))
 
11
    assert_exception(ValueError, lambda: ImagePalette("RGB", list(range(256))*2))
 
12
 
 
13
def test_getcolor():
 
14
 
 
15
    palette = ImagePalette()
 
16
 
 
17
    map = {}
 
18
    for i in range(256):
 
19
        map[palette.getcolor((i, i, i))] = i
 
20
 
 
21
    assert_equal(len(map), 256)
 
22
    assert_exception(ValueError, lambda: palette.getcolor((1, 2, 3)))
 
23
 
 
24
def test_file():
 
25
 
 
26
    palette = ImagePalette()
 
27
 
 
28
    file = tempfile("temp.lut")
 
29
 
 
30
    palette.save(file)
 
31
    
 
32
    from PIL.ImagePalette import load, raw
 
33
 
 
34
    p = load(file)
 
35
 
 
36
    # load returns raw palette information
 
37
    assert_equal(len(p[0]), 768)
 
38
    assert_equal(p[1], "RGB")
 
39
 
 
40
    p = raw(p[1], p[0])
 
41
    assert_true(isinstance(p, ImagePalette))
 
42
 
 
43
    
 
44