~ubuntu-branches/ubuntu/saucy/python-imaging/saucy-proposed

« back to all changes in this revision

Viewing changes to Tests/test_imagefile.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-01-31 20:49:20 UTC
  • mfrom: (27.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130131204920-b5zshy6vgfvdionl
Tags: 1.1.7+1.7.8-1ubuntu1
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 ImageFile
 
5
 
 
6
# save original block sizes
 
7
MAXBLOCK = ImageFile.MAXBLOCK
 
8
SAFEBLOCK = ImageFile.SAFEBLOCK
 
9
 
 
10
def test_parser():
 
11
 
 
12
    def roundtrip(format):
 
13
 
 
14
        im = lena("L").resize((1000, 1000))
 
15
        if format in ("MSP", "XBM"):
 
16
            im = im.convert("1")
 
17
 
 
18
        file = BytesIO()
 
19
 
 
20
        im.save(file, format)
 
21
 
 
22
        data = file.getvalue()
 
23
 
 
24
        parser = ImageFile.Parser()
 
25
        parser.feed(data)
 
26
        imOut = parser.close()
 
27
 
 
28
        return im, imOut
 
29
 
 
30
    assert_image_equal(*roundtrip("BMP"))
 
31
    assert_image_equal(*roundtrip("GIF"))
 
32
    assert_image_equal(*roundtrip("IM"))
 
33
    assert_image_equal(*roundtrip("MSP"))
 
34
    try:
 
35
        # force multiple blocks in PNG driver
 
36
        ImageFile.MAXBLOCK = 8192
 
37
        assert_image_equal(*roundtrip("PNG"))
 
38
    finally:
 
39
        ImageFile.MAXBLOCK = MAXBLOCK
 
40
    assert_image_equal(*roundtrip("PPM"))
 
41
    assert_image_equal(*roundtrip("TIFF"))
 
42
    assert_image_equal(*roundtrip("XBM"))
 
43
    #assert_image_equal(*roundtrip("EPS"))      #no eps_decoder
 
44
    assert_image_equal(*roundtrip("TGA"))
 
45
    assert_image_equal(*roundtrip("PCX"))
 
46
 
 
47
    im1, im2 = roundtrip("JPEG") # lossy compression
 
48
    assert_image(im1, im2.mode, im2.size)
 
49
 
 
50
    assert_exception(IOError, lambda: roundtrip("PDF"))
 
51
 
 
52
 
 
53
def test_safeblock():
 
54
 
 
55
    im1 = lena()
 
56
 
 
57
    try:
 
58
        ImageFile.SAFEBLOCK = 1
 
59
        im2 = fromstring(tostring(im1, "PNG"))
 
60
    finally:
 
61
        ImageFile.SAFEBLOCK = SAFEBLOCK
 
62
    
 
63
    assert_image_equal(im1, im2)