Fix tox test running: port selftest.py to Python 3; make it clear Python 2.5 is no longer supported (its support is broken in many ways in this branch); remove bundled doctest.py module (it is in stdlib since forever); remove extra stuff from tox.ini

This commit is contained in:
Mikhail Korobov 2012-10-30 00:50:20 +06:00 committed by Brian Crowell
parent c952134e00
commit decabcf96a
3 changed files with 31 additions and 36 deletions

View File

@ -1,5 +1,5 @@
# minimal sanity check # minimal sanity check
from __future__ import print_function
ROOT = "." ROOT = "."
import os, sys import os, sys
@ -13,7 +13,7 @@ from PIL import ImageMath
try: try:
Image.core.ping Image.core.ping
except ImportError as v: except ImportError as v:
print "***", v print("***", v)
sys.exit() sys.exit()
except AttributeError: except AttributeError:
pass pass
@ -49,19 +49,19 @@ def testimage():
('PPM', 'RGB', (128, 128)) ('PPM', 'RGB', (128, 128))
>>> try: >>> try:
... _info(Image.open(os.path.join(ROOT, "Images/lena.jpg"))) ... _info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
... except IOError, v: ... except IOError as v:
... print v ... print(v)
('JPEG', 'RGB', (128, 128)) ('JPEG', 'RGB', (128, 128))
PIL doesn't actually load the image data until it's needed, PIL doesn't actually load the image data until it's needed,
or you call the "load" method: or you call the "load" method:
>>> im = Image.open(os.path.join(ROOT, "Images/lena.ppm")) >>> im = Image.open(os.path.join(ROOT, "Images/lena.ppm"))
>>> print im.im # internal image attribute >>> print(im.im) # internal image attribute
None None
>>> a = im.load() >>> a = im.load()
>>> type(im.im) >>> type(im.im) # doctest: +ELLIPSIS
<type 'ImagingCore'> <... '...ImagingCore'>
You can apply many different operations on images. Most You can apply many different operations on images. Most
operations return a new image: operations return a new image:
@ -89,17 +89,17 @@ def testimage():
2 2
>>> len(im.histogram()) >>> len(im.histogram())
768 768
>>> _info(im.point(range(256)*3)) >>> _info(im.point(list(range(256))*3))
(None, 'RGB', (128, 128)) (None, 'RGB', (128, 128))
>>> _info(im.resize((64, 64))) >>> _info(im.resize((64, 64)))
(None, 'RGB', (64, 64)) (None, 'RGB', (64, 64))
>>> _info(im.rotate(45)) >>> _info(im.rotate(45))
(None, 'RGB', (128, 128)) (None, 'RGB', (128, 128))
>>> map(_info, im.split()) >>> [_info(ch) for ch in im.split()]
[(None, 'L', (128, 128)), (None, 'L', (128, 128)), (None, 'L', (128, 128))] [(None, 'L', (128, 128)), (None, 'L', (128, 128)), (None, 'L', (128, 128))]
>>> len(im.convert("1").tobitmap()) >>> len(im.convert("1").tobitmap())
10456 10456
>>> len(im.tostring()) >>> len(im.tobytes())
49152 49152
>>> _info(im.transform((512, 512), Image.AFFINE, (1,0,0,0,1,0))) >>> _info(im.transform((512, 512), Image.AFFINE, (1,0,0,0,1,0)))
(None, 'RGB', (512, 512)) (None, 'RGB', (512, 512))
@ -159,15 +159,15 @@ def check_module(feature, module):
try: try:
__import__("PIL." + module) __import__("PIL." + module)
except ImportError: except ImportError:
print "***", feature, "support not installed" print("***", feature, "support not installed")
else: else:
print "---", feature, "support ok" print("---", feature, "support ok")
def check_codec(feature, codec): def check_codec(feature, codec):
if codec + "_encoder" not in dir(Image.core): if codec + "_encoder" not in dir(Image.core):
print "***", feature, "support not installed" print("***", feature, "support not installed")
else: else:
print "---", feature, "support ok" print("---", feature, "support ok")
if __name__ == "__main__": if __name__ == "__main__":
@ -175,28 +175,28 @@ if __name__ == "__main__":
exit_status = 0 exit_status = 0
print "-"*68 print("-"*68)
print "PIL", Image.VERSION, "TEST SUMMARY " print("PIL", Image.VERSION, "TEST SUMMARY ")
print "-"*68 print("-"*68)
print "Python modules loaded from", os.path.dirname(Image.__file__) print("Python modules loaded from", os.path.dirname(Image.__file__))
print "Binary modules loaded from", os.path.dirname(Image.core.__file__) print("Binary modules loaded from", os.path.dirname(Image.core.__file__))
print "-"*68 print("-"*68)
check_module("PIL CORE", "_imaging") check_module("PIL CORE", "_imaging")
check_module("TKINTER", "_imagingtk") check_module("TKINTER", "_imagingtk")
check_codec("JPEG", "jpeg") check_codec("JPEG", "jpeg")
check_codec("ZLIB (PNG/ZIP)", "zip") check_codec("ZLIB (PNG/ZIP)", "zip")
check_module("FREETYPE2", "_imagingft") check_module("FREETYPE2", "_imagingft")
check_module("LITTLECMS", "_imagingcms") check_module("LITTLECMS", "_imagingcms")
print "-"*68 print("-"*68)
# use doctest to make sure the test program behaves as documented! # use doctest to make sure the test program behaves as documented!
import doctest, selftest import doctest, selftest
print "Running selftest:" print("Running selftest:")
status = doctest.testmod(selftest) status = doctest.testmod(selftest)
if status[0]: if status[0]:
print "*** %s tests of %d failed." % status print("*** %s tests of %d failed." % status)
exit_status = 1 exit_status = 1
else: else:
print "--- %s tests passed." % status[1] print("--- %s tests passed." % status[1])
sys.exit(exit_status) sys.exit(exit_status)

View File

@ -462,6 +462,12 @@ setup(
"Topic :: Multimedia :: Graphics :: Capture :: Screen Capture", "Topic :: Multimedia :: Graphics :: Capture :: Screen Capture",
"Topic :: Multimedia :: Graphics :: Graphics Conversion", "Topic :: Multimedia :: Graphics :: Graphics Conversion",
"Topic :: Multimedia :: Graphics :: Viewers", "Topic :: Multimedia :: Graphics :: Viewers",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
], ],
cmdclass={"build_ext": pil_build_ext}, cmdclass={"build_ext": pil_build_ext},
ext_modules=[Extension("_imaging", ["_imaging.c"])], ext_modules=[Extension("_imaging", ["_imaging.c"])],

13
tox.ini
View File

@ -4,19 +4,8 @@
# and then run "tox" from this directory. # and then run "tox" from this directory.
[tox] [tox]
envlist = py25, py26, py27, py32, pypy envlist = py26, py27, py32, py33, pypy
[testenv] [testenv]
commands = commands =
{envpython} setup.py clean
rm -rf build dist
{envpython} setup.py install
{envpython} selftest.py {envpython} selftest.py
[testenv:py32]
commands =
{envpython} setup.py clean
rm -rf build dist
{envpython} setup.py install
2to3 -w -n -o . --add-suffix=3 selftest.py
{envpython} selftest.py3