From a9879b14387f4ee8439b4fc53ef55602b6a48db2 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sun, 14 Feb 2010 18:33:01 +0000 Subject: [1.1.X] Fixed #6054: work around PIL's installation brokeness by detecting either of the two ways it can end up being installed. Backport of [12429] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12430 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/models.py | 14 +++++++++----- tests/regressiontests/file_storage/tests.py | 10 +++++++--- tests/regressiontests/model_fields/models.py | 11 ++++++++--- 3 files changed, 24 insertions(+), 11 deletions(-) (limited to 'tests') diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 0fd24c18ad..92e05e19ef 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -99,11 +99,15 @@ class TextFile(models.Model): return self.description try: - # If PIL is available, try testing ImageFields. - # Checking for the existence of Image is enough for CPython, but - # for PyPy, you need to check for the underlying modules - # If PIL is not available, ImageField tests are omitted. - from PIL import Image, _imaging + # If PIL is available, try testing ImageFields. Checking for the existence + # of Image is enough for CPython, but for PyPy, you need to check for the + # underlying modules If PIL is not available, ImageField tests are omitted. + # Try to import PIL in either of the two ways it can end up installed. + try: + from PIL import Image, _imaging + except ImportError: + import Image, _imaging + test_images = True class ImageFile(models.Model): diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py index c228764e06..81ea48950c 100644 --- a/tests/regressiontests/file_storage/tests.py +++ b/tests/regressiontests/file_storage/tests.py @@ -18,12 +18,16 @@ try: except ImportError: import dummy_threading as threading +# Try to import PIL in either of the two ways it can end up installed. +# Checking for the existence of Image is enough for CPython, but +# for PyPy, you need to check for the underlying modules try: - # Checking for the existence of Image is enough for CPython, but - # for PyPy, you need to check for the underlying modules from PIL import Image, _imaging except ImportError: - Image = None + try: + import Image, _imaging + except ImportError: + Image = None class FileStorageTests(unittest.TestCase): storage_class = FileSystemStorage diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py index 462e96874b..2fed5195dd 100644 --- a/tests/regressiontests/model_fields/models.py +++ b/tests/regressiontests/model_fields/models.py @@ -6,12 +6,17 @@ try: except ImportError: from django.utils import _decimal as decimal # Python 2.3 fallback +# Try to import PIL in either of the two ways it can end up installed. +# Checking for the existence of Image is enough for CPython, but for PyPy, +# you need to check for the underlying modules. + try: - # Checking for the existence of Image is enough for CPython, but for PyPy, - # you need to check for the underlying modules. from PIL import Image, _imaging except ImportError: - Image = None + try: + import Image, _imaging + except ImportError: + Image = None from django.core.files.storage import FileSystemStorage from django.db import models -- cgit v1.3