diff --git a/.travis.yml b/.travis.yml index 23225dbbb..b5adc2da7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,8 +30,10 @@ matrix: - python: '3.5' - python: '3.5' dist: trusty + env: PYTHONOPTIMIZE=1 - python: '3.4' dist: trusty + env: PYTHONOPTIMIZE=2 - env: DOCKER="alpine" DOCKER_TAG="pytest" - env: DOCKER="arch" DOCKER_TAG="pytest" # contains PyQt5 - env: DOCKER="ubuntu-trusty-x86" DOCKER_TAG="pytest" diff --git a/Tests/test_image_access.py b/Tests/test_image_access.py index 7a9378bbd..a7e39a499 100644 --- a/Tests/test_image_access.py +++ b/Tests/test_image_access.py @@ -1,15 +1,20 @@ from helper import unittest, PillowTestCase, hopper, on_appveyor -try: - from PIL import PyAccess -except ImportError: - # Skip in setUp() - pass - from PIL import Image import sys import os +# CFFI imports pycparser which doesn't support PYTHONOPTIMIZE=2 +# https://github.com/eliben/pycparser/pull/198#issuecomment-317001670 +if os.environ.get("PYTHONOPTIMIZE") == "2": + cffi = None +else: + try: + from PIL import PyAccess + import cffi + except ImportError: + cffi = None + class AccessTest(PillowTestCase): # initial value @@ -113,38 +118,20 @@ class TestImageGetPixel(AccessTest): self.check(mode, 2**16-1) +@unittest.skipIf(cffi is None, "No cffi") class TestCffiPutPixel(TestImagePutPixel): _need_cffi_access = True - def setUp(self): - try: - import cffi - assert cffi # silence warning - except ImportError: - self.skipTest("No cffi") - +@unittest.skipIf(cffi is None, "No cffi") class TestCffiGetPixel(TestImageGetPixel): _need_cffi_access = True - def setUp(self): - try: - import cffi - assert cffi # silence warning - except ImportError: - self.skipTest("No cffi") - +@unittest.skipIf(cffi is None, "No cffi") class TestCffi(AccessTest): _need_cffi_access = True - def setUp(self): - try: - import cffi - assert cffi # silence warning - except ImportError: - self.skipTest("No cffi") - def _test_get_access(self, im): """Do we get the same thing as the old pixel access diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index f2116bdc4..82108638c 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -215,7 +215,7 @@ class TestImageFont(PillowTestCase): # Act/Assert self.assertRaises( - AssertionError, + ValueError, draw.multiline_text, (0, 0), TEST_TEXT, font=ttf, align="unknown") def test_draw_align(self): diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 02fa865aa..5cf9ff25c 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -246,7 +246,7 @@ class ImageDraw(object): elif align == "right": left += (max_width - widths[idx]) else: - assert False, 'align must be "left", "center" or "right"' + raise ValueError('align must be "left", "center" or "right"') self.text((left, top), line, fill, font, anchor, direction=direction, features=features) top += line_spacing diff --git a/src/PIL/ImageTk.py b/src/PIL/ImageTk.py index 17bf32f62..c56f5560a 100644 --- a/src/PIL/ImageTk.py +++ b/src/PIL/ImageTk.py @@ -32,13 +32,6 @@ if sys.version_info.major > 2: else: import Tkinter as tkinter -# required for pypy, which always has cffi installed -try: - from cffi import FFI - ffi = FFI() -except ImportError: - pass - from . import Image from io import BytesIO @@ -192,7 +185,11 @@ class PhotoImage(object): from . import _imagingtk try: if hasattr(tk, 'interp'): - # Pypy is using a ffi cdata element + # Required for PyPy, which always has CFFI installed + from cffi import FFI + ffi = FFI() + + # PyPy is using an FFI CDATA element # (Pdb) self.tk.interp # _imagingtk.tkinit( diff --git a/src/PIL/__init__.py b/src/PIL/__init__.py index a07280e31..bc8cfed8c 100644 --- a/src/PIL/__init__.py +++ b/src/PIL/__init__.py @@ -1,4 +1,4 @@ -"""Pillow {} (Fork of the Python Imaging Library) +"""Pillow (Fork of the Python Imaging Library) Pillow is the friendly PIL fork by Alex Clark and Contributors. https://github.com/python-pillow/Pillow/ @@ -24,8 +24,6 @@ PILLOW_VERSION = __version__ = _version.__version__ del _version -__doc__ = __doc__.format(__version__) # include version in docstring - _plugins = ['BlpImagePlugin', 'BmpImagePlugin',