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

« back to all changes in this revision

Viewing changes to selftest.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
1
# minimal sanity check
2
 
 
 
2
from __future__ import print_function
3
3
ROOT = "."
4
4
 
5
5
import os, sys
12
12
 
13
13
try:
14
14
    Image.core.ping
15
 
except ImportError, v:
16
 
    print "***", v
 
15
except ImportError as v:
 
16
    print("***", v)
17
17
    sys.exit()
18
18
except AttributeError:
19
19
    pass
49
49
    ('PPM', 'RGB', (128, 128))
50
50
    >>> try:
51
51
    ...  _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
52
 
    ... except IOError, v:
53
 
    ...  print v
 
52
    ... except IOError as v:
 
53
    ...  print(v)
54
54
    ('JPEG', 'RGB', (128, 128))
55
55
 
56
56
    PIL doesn't actually load the image data until it's needed,
57
57
    or you call the "load" method:
58
58
 
59
59
    >>> im = Image.open(os.path.join(ROOT, "Images/lena.ppm"))
60
 
    >>> print im.im # internal image attribute
 
60
    >>> print(im.im) # internal image attribute
61
61
    None
62
62
    >>> a = im.load()
63
 
    >>> type(im.im)
64
 
    <type 'ImagingCore'>
 
63
    >>> type(im.im) # doctest: +ELLIPSIS
 
64
    <... '...ImagingCore'>
65
65
 
66
66
    You can apply many different operations on images.  Most
67
67
    operations return a new image:
89
89
    2
90
90
    >>> len(im.histogram())
91
91
    768
92
 
    >>> _info(im.point(range(256)*3))
 
92
    >>> _info(im.point(list(range(256))*3))
93
93
    (None, 'RGB', (128, 128))
94
94
    >>> _info(im.resize((64, 64)))
95
95
    (None, 'RGB', (64, 64))
96
96
    >>> _info(im.rotate(45))
97
97
    (None, 'RGB', (128, 128))
98
 
    >>> map(_info, im.split())
 
98
    >>> [_info(ch) for ch in im.split()]
99
99
    [(None, 'L', (128, 128)), (None, 'L', (128, 128)), (None, 'L', (128, 128))]
100
100
    >>> len(im.convert("1").tobitmap())
101
101
    10456
102
 
    >>> len(im.tostring())
 
102
    >>> len(im.tobytes())
103
103
    49152
104
104
    >>> _info(im.transform((512, 512), Image.AFFINE, (1,0,0,0,1,0)))
105
105
    (None, 'RGB', (512, 512))
159
159
    try:
160
160
        __import__("PIL." + module)
161
161
    except ImportError:
162
 
        print "***", feature, "support not installed"
 
162
        print("***", feature, "support not installed")
163
163
    else:
164
 
        print "---", feature, "support ok"
 
164
        print("---", feature, "support ok")
165
165
 
166
166
def check_codec(feature, codec):
167
167
    if codec + "_encoder" not in dir(Image.core):
168
 
        print "***", feature, "support not installed"
 
168
        print("***", feature, "support not installed")
169
169
    else:
170
 
        print "---", feature, "support ok"
 
170
        print("---", feature, "support ok")
171
171
 
172
172
 
173
173
if __name__ == "__main__":
175
175
 
176
176
    exit_status = 0
177
177
 
178
 
    print "-"*68
179
 
    print "PIL", Image.VERSION, "TEST SUMMARY "
180
 
    print "-"*68
181
 
    print "Python modules loaded from", os.path.dirname(Image.__file__)
182
 
    print "Binary modules loaded from", os.path.dirname(Image.core.__file__)
183
 
    print "-"*68
 
178
    print("-"*68)
 
179
    print("PIL", Image.VERSION, "TEST SUMMARY ")
 
180
    print("-"*68)
 
181
    print("Python modules loaded from", os.path.dirname(Image.__file__))
 
182
    print("Binary modules loaded from", os.path.dirname(Image.core.__file__))
 
183
    print("-"*68)
184
184
    check_module("PIL CORE", "_imaging")
185
185
    check_module("TKINTER", "_imagingtk")
186
186
    check_codec("JPEG", "jpeg")
187
187
    check_codec("ZLIB (PNG/ZIP)", "zip")
188
188
    check_module("FREETYPE2", "_imagingft")
189
189
    check_module("LITTLECMS", "_imagingcms")
190
 
    print "-"*68
 
190
    print("-"*68)
191
191
 
192
192
    # use doctest to make sure the test program behaves as documented!
193
193
    import doctest, selftest
194
 
    print "Running selftest:"
 
194
    print("Running selftest:")
195
195
    status = doctest.testmod(selftest)
196
196
    if status[0]:
197
 
        print "*** %s tests of %d failed." % status
 
197
        print("*** %s tests of %d failed." % status)
198
198
        exit_status = 1
199
199
    else:
200
 
        print "--- %s tests passed." % status[1]
 
200
        print("--- %s tests passed." % status[1])
201
201
 
202
202
    sys.exit(exit_status)