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

« back to all changes in this revision

Viewing changes to Tests/test_imagestat.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 ImageStat
 
5
 
 
6
def test_sanity():
 
7
 
 
8
    im = lena()
 
9
 
 
10
    st = ImageStat.Stat(im)
 
11
    st = ImageStat.Stat(im.histogram())
 
12
    st = ImageStat.Stat(im, Image.new("1", im.size, 1))
 
13
 
 
14
    assert_no_exception(lambda: st.extrema)
 
15
    assert_no_exception(lambda: st.sum)
 
16
    assert_no_exception(lambda: st.mean)
 
17
    assert_no_exception(lambda: st.median)
 
18
    assert_no_exception(lambda: st.rms)
 
19
    assert_no_exception(lambda: st.sum2)
 
20
    assert_no_exception(lambda: st.var)
 
21
    assert_no_exception(lambda: st.stddev)
 
22
    assert_exception(AttributeError, lambda: st.spam)
 
23
 
 
24
    assert_exception(TypeError, lambda: ImageStat.Stat(1))
 
25
 
 
26
def test_lena():
 
27
 
 
28
    im = lena()
 
29
 
 
30
    st = ImageStat.Stat(im)
 
31
 
 
32
    # verify a few values
 
33
    assert_equal(st.extrema[0], (61, 255))
 
34
    assert_equal(st.median[0], 197)
 
35
    assert_equal(st.sum[0], 2954416)
 
36
    assert_equal(st.sum[1], 2027250)
 
37
    assert_equal(st.sum[2], 1727331)
 
38
 
 
39
def test_constant():
 
40
 
 
41
    im = Image.new("L", (128, 128), 128)
 
42
 
 
43
    st = ImageStat.Stat(im)
 
44
 
 
45
    assert_equal(st.extrema[0], (128, 128))
 
46
    assert_equal(st.sum[0], 128**3)
 
47
    assert_equal(st.sum2[0], 128**4)
 
48
    assert_equal(st.mean[0], 128)
 
49
    assert_equal(st.median[0], 128)
 
50
    assert_equal(st.rms[0], 128)
 
51
    assert_equal(st.var[0], 0)
 
52
    assert_equal(st.stddev[0], 0)